os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_main.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32\sfile\sf_main.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "sf_std.h"
sl@0
    19
#include "sf_plugin.h"
sl@0
    20
#include "sf_file_cache.h"	// for TClosedFileUtils
sl@0
    21
#include "sf_memory_man.h"
sl@0
    22
sl@0
    23
#ifdef __WINS__
sl@0
    24
#include <emulator.h>
sl@0
    25
#include <e32wins.h>
sl@0
    26
#endif
sl@0
    27
#include "d32btrace.h"
sl@0
    28
sl@0
    29
// define this macro to enable tracing very early on in the boot sequence
sl@0
    30
//#define __ENABLE_TRACE__
sl@0
    31
sl@0
    32
#ifdef __EPOC32__
sl@0
    33
_LIT(KStartupExeSysBinName,"Z:\\Sys\\Bin\\ESTART.EXE");
sl@0
    34
#else
sl@0
    35
_LIT(KStartupExeName,"E32STRT.EXE");
sl@0
    36
_LIT(KStartupExeSysBinName,"E32STRT.EXE");
sl@0
    37
#endif
sl@0
    38
sl@0
    39
//const TInt KSessionNotifyListGranularity=16; //-- not used anywhere
sl@0
    40
sl@0
    41
// patch ldds should specify this as their third uid
sl@0
    42
//const TInt KPatchLddUidValue=0x100000cc; //-- not used anywhere
sl@0
    43
sl@0
    44
_LIT(KFileServerName,"!FileServer");
sl@0
    45
sl@0
    46
void CServerFs::New()
sl@0
    47
//
sl@0
    48
// Create a new CServerFs.
sl@0
    49
//
sl@0
    50
	{
sl@0
    51
	TheFileServer=new CServerFs(EPriority);
sl@0
    52
	__ASSERT_ALWAYS(TheFileServer!=NULL,Fault(EMainCreateServer));
sl@0
    53
	TInt r = TheFileServer->iSessionQueueLock.CreateLocal();
sl@0
    54
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainCreateServer));
sl@0
    55
	r=TheFileServer->Start(KFileServerName);
sl@0
    56
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainStartServer));
sl@0
    57
	}
sl@0
    58
sl@0
    59
sl@0
    60
CServerFs::CServerFs(TInt aPriority)
sl@0
    61
//
sl@0
    62
//Constructor.
sl@0
    63
// 
sl@0
    64
	: CServer2(aPriority,EGlobalSharableSessions)
sl@0
    65
	{
sl@0
    66
	}
sl@0
    67
sl@0
    68
CServerFs::~CServerFs()
sl@0
    69
//
sl@0
    70
//Destructor.
sl@0
    71
// 
sl@0
    72
	{
sl@0
    73
	iSessionQueueLock.Close();
sl@0
    74
	}
sl@0
    75
sl@0
    76
void CServerFs::RunL()
sl@0
    77
// 
sl@0
    78
// calls CServer2::RunL
sl@0
    79
//
sl@0
    80
	{
sl@0
    81
	TInt fn = Message().Function();
sl@0
    82
sl@0
    83
	// CServer2::DoConnectL() manipulates iSessionQ & so does CSession2::~CSession2().
sl@0
    84
	// Unfortunately the session is deleted from a seperate thread (the disconnect 
sl@0
    85
	// thread) so we need a lock to protect it.
sl@0
    86
	if (fn == RMessage2::EConnect)
sl@0
    87
		{
sl@0
    88
		SessionQueueLockWait();		// lock
sl@0
    89
		CServer2::RunL();
sl@0
    90
		SessionQueueLockSignal();	// unlock
sl@0
    91
		}
sl@0
    92
	else
sl@0
    93
		{
sl@0
    94
		CServer2::RunL();
sl@0
    95
		}
sl@0
    96
	}
sl@0
    97
sl@0
    98
CSessionFs* CServerFs::operator[](TInt anIndex)
sl@0
    99
//
sl@0
   100
// Indexing operator used by DoFsListOpenFiles
sl@0
   101
//
sl@0
   102
	{
sl@0
   103
	__ASSERT_DEBUG(anIndex>=0,Fault(ESvrBadSessionIndex));
sl@0
   104
	iSessionIter.SetToFirst();
sl@0
   105
	while (anIndex--)
sl@0
   106
		iSessionIter++;
sl@0
   107
	CSessionFs* ses=(CSessionFs*)&(*iSessionIter);
sl@0
   108
	return(ses);
sl@0
   109
	}
sl@0
   110
sl@0
   111
_LIT(KPrivatePath,"?:\\Private\\");
sl@0
   112
CSession2* CServerFs::NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const
sl@0
   113
//
sl@0
   114
// Create a new client session for this server.
sl@0
   115
//
sl@0
   116
	{
sl@0
   117
	TVersion v(KF32MajorVersionNumber,KF32MinorVersionNumber,KF32BuildVersionNumber);
sl@0
   118
	TBool r=User::QueryVersionSupported(v,aVersion);
sl@0
   119
	if (!r)
sl@0
   120
		User::Leave(KErrNotSupported);
sl@0
   121
	__CALL(if(UserHeapAllocFailCount>=0){__UHEAP_FAILNEXT(10);}); // Create session must succeed
sl@0
   122
	CSessionFs* ses=CSessionFs::NewL();
sl@0
   123
	CleanupStack::PushL(ses);
sl@0
   124
	TUid aUid = aMessage.SecureId();
sl@0
   125
	TBuf<30> thePath = KPrivatePath();	
sl@0
   126
	thePath[0] = (TUint8) RFs::GetSystemDriveChar();
sl@0
   127
	thePath.AppendNumFixedWidth(aUid.iUid, EHex, 8);
sl@0
   128
	thePath.Append(KSlash);
sl@0
   129
	HBufC* pP=thePath.AllocL(); 
sl@0
   130
	ses->SetPath(pP);
sl@0
   131
	__CALL(if (UserHeapAllocFailCount>=0){__UHEAP_FAILNEXT(UserHeapAllocFailCount);});
sl@0
   132
sl@0
   133
sl@0
   134
	RThread idClient;
sl@0
   135
	User::LeaveIfError(aMessage.Client(idClient, EOwnerThread));
sl@0
   136
	ses->SetThreadId(idClient.Id());
sl@0
   137
	idClient.Close();
sl@0
   138
sl@0
   139
	CleanupStack::Pop(); //ses
sl@0
   140
sl@0
   141
	return(ses);
sl@0
   142
	}
sl@0
   143
sl@0
   144
void CSessionFs::ServiceL(const RMessage2& aMessage)
sl@0
   145
//
sl@0
   146
// Service this message for the server
sl@0
   147
//
sl@0
   148
	{
sl@0
   149
	__CALL( if (SimulateError(&aMessage)) { aMessage.Complete(ErrorCondition); return; } );
sl@0
   150
	const TInt ipcFunction = aMessage.Function() & KIpcFunctionMask;
sl@0
   151
	
sl@0
   152
	if((ipcFunction) >= EMaxClientOperations)
sl@0
   153
		{
sl@0
   154
		__THRD_PRINT1(_L("CSessionFs::DoServiceL() - func 0x%x KErrNotSupported"), ipcFunction);
sl@0
   155
		aMessage.Complete(KErrNotSupported);
sl@0
   156
		return;
sl@0
   157
		}
sl@0
   158
	 
sl@0
   159
	const TOperation& oP = OperationArray[ipcFunction];
sl@0
   160
	CFsClientMessageRequest* pR = NULL;
sl@0
   161
	TInt r = RequestAllocator::GetMessageRequest(oP, aMessage, pR);
sl@0
   162
	if(r != KErrNone)
sl@0
   163
		{
sl@0
   164
		if(r == KErrBadHandle)
sl@0
   165
			{
sl@0
   166
			_LIT(KPanic,"Panic");
sl@0
   167
			aMessage.Panic(KPanic, r);
sl@0
   168
			return;
sl@0
   169
			}
sl@0
   170
		aMessage.Complete(r);
sl@0
   171
		return;
sl@0
   172
		}
sl@0
   173
	pR->Set(aMessage, oP, this);
sl@0
   174
	__PRINT4TEMP(_L("***** Received Message sess %08x req %08x func 0x%x - %S"), this, pR, ipcFunction, GetFunctionName(ipcFunction));
sl@0
   175
	pR->Dispatch();
sl@0
   176
	}
sl@0
   177
sl@0
   178
void CActiveSchedulerFs::New()
sl@0
   179
//
sl@0
   180
// Create and install the active scheduler.
sl@0
   181
//
sl@0
   182
	{
sl@0
   183
sl@0
   184
	CActiveSchedulerFs* pA=new CActiveSchedulerFs;
sl@0
   185
	__ASSERT_ALWAYS(pA!=NULL,Fault(EMainCreateScheduler));
sl@0
   186
	CActiveScheduler::Install(pA);
sl@0
   187
	}
sl@0
   188
sl@0
   189
void CActiveSchedulerFs::Error(TInt anError) const
sl@0
   190
//
sl@0
   191
// Called if any Run() method leaves, which should never happen.
sl@0
   192
//
sl@0
   193
	{
sl@0
   194
sl@0
   195
	__PRINT1(_L("FileSystemActiveScheduler Error %d"),anError);
sl@0
   196
	User::Panic(_L("FSRV-ERR"),anError);
sl@0
   197
	}
sl@0
   198
sl@0
   199
sl@0
   200
void createAllL()
sl@0
   201
//
sl@0
   202
// Create the initial objects
sl@0
   203
//
sl@0
   204
	{
sl@0
   205
//
sl@0
   206
// First we need to create all the containers.
sl@0
   207
//
sl@0
   208
	TheContainer=CFsObjectConIx::NewL();
sl@0
   209
	FileSystems=TheContainer->CreateL();
sl@0
   210
	Extensions=TheContainer->CreateL();
sl@0
   211
	ProxyDrives=TheContainer->CreateL();
sl@0
   212
	Files=TheContainer->CreateL();
sl@0
   213
	FileShares=TheContainer->CreateL();
sl@0
   214
	Dirs=TheContainer->CreateL();
sl@0
   215
	Formats=TheContainer->CreateL();
sl@0
   216
	RawDisks=TheContainer->CreateL();
sl@0
   217
	TClosedFileUtils::InitL();
sl@0
   218
sl@0
   219
//
sl@0
   220
// Initialize the drives
sl@0
   221
//
sl@0
   222
	for (TInt i=0;i<KMaxDrives;i++)
sl@0
   223
		TheDrives[i].CreateL(i);
sl@0
   224
sl@0
   225
//
sl@0
   226
// Next we need to create the ROM file system.
sl@0
   227
//
sl@0
   228
#if defined(__EPOC32__)
sl@0
   229
	InstallRomFileSystemL();
sl@0
   230
	CFileSystem* romFs=GetFileSystem(_L("Rom"));
sl@0
   231
//#ifndef __DATA_CAGING__	
sl@0
   232
	TheDefaultPath=_L("Z:\\"); // Temporarily set the default path to the ROM
sl@0
   233
//#endif
sl@0
   234
	TheDrives[EDriveZ].SetAtt(KDriveAttRom|KDriveAttInternal);
sl@0
   235
	TheDrives[EDriveZ].GetFSys()=romFs;
sl@0
   236
	TInt r=FsThreadManager::InitDrive(EDriveZ,ETrue);
sl@0
   237
	User::LeaveIfError(r);
sl@0
   238
#endif
sl@0
   239
	}
sl@0
   240
sl@0
   241
sl@0
   242
TInt InitializeLocalFileSystem(const TDesC& aName)
sl@0
   243
//
sl@0
   244
// Initialize the local file system
sl@0
   245
//
sl@0
   246
	{
sl@0
   247
sl@0
   248
    __PRINT(_L("InitializeLocalFileSystem"));
sl@0
   249
    CFileSystem* localFileSystem=GetFileSystem(aName);
sl@0
   250
	__ASSERT_DEBUG(localFileSystem!=NULL,Fault(EMainGetLocalFileSystem));
sl@0
   251
	if(localFileSystem == NULL)
sl@0
   252
		return KErrNotFound;
sl@0
   253
#if defined(__WINS__)
sl@0
   254
	TheDrives[EDriveZ].GetFSys()=localFileSystem;
sl@0
   255
	TheDrives[EDriveZ].SetAtt(KDriveAttRom|KDriveAttInternal);
sl@0
   256
	TInt r=FsThreadManager::InitDrive(EDriveZ,ETrue);
sl@0
   257
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainInitialiseRomFs));
sl@0
   258
#endif
sl@0
   259
sl@0
   260
//
sl@0
   261
// Initialize the default path
sl@0
   262
//
sl@0
   263
//#ifndef __DATA_CAGING__
sl@0
   264
#if !defined(__WINS__)
sl@0
   265
	TInt r;
sl@0
   266
#endif
sl@0
   267
	r=localFileSystem->DefaultPath(TheDefaultPath);
sl@0
   268
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainGetLocalDefaultPath));
sl@0
   269
//#endif
sl@0
   270
sl@0
   271
	LocalFileSystemInitialized=ETrue;
sl@0
   272
sl@0
   273
	return KErrNone;
sl@0
   274
sl@0
   275
	}
sl@0
   276
sl@0
   277
_LIT(KMediaLddName, "ELOCD");
sl@0
   278
sl@0
   279
TInt StartupThread(TAny*)
sl@0
   280
//
sl@0
   281
// The startup thread.
sl@0
   282
//
sl@0
   283
	{
sl@0
   284
sl@0
   285
    __PRINT(_L("StartupThread"));
sl@0
   286
	User::SetCritical(User::ESystemCritical);
sl@0
   287
sl@0
   288
	TInt r;
sl@0
   289
#ifdef SYMBIAN_FTRACE_ENABLE
sl@0
   290
	r = User::LoadLogicalDevice(_L("D_FTRACE"));	
sl@0
   291
	__PRINT1(_L("User::LoadLogicalDevice(D_FTRACE) returns %d"),r);
sl@0
   292
	__ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists,Fault(ETraceLddLoadFailure));
sl@0
   293
sl@0
   294
	r = TheFtrace.Open(EOwnerProcess);
sl@0
   295
	__ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists,Fault(ETraceLddLoadFailure));
sl@0
   296
#endif
sl@0
   297
sl@0
   298
#if defined (__ENABLE_TRACE__)
sl@0
   299
		{
sl@0
   300
		RBTrace trace;
sl@0
   301
		
sl@0
   302
		trace.Open();
sl@0
   303
		
sl@0
   304
//		trace.SetMode(RBTrace::EEnable + RBTrace::EFreeRunning);
sl@0
   305
		trace.SetFilter(BTrace::EThreadIdentification,1);
sl@0
   306
sl@0
   307
		trace.SetFilter(UTF::EBorder,1);
sl@0
   308
		trace.SetFilter(UTF::EError,1);
sl@0
   309
sl@0
   310
		trace.SetFilter2(EF32TraceUidEfsrv,1);
sl@0
   311
//		trace.SetFilter2(EF32TraceUidFileSys,1);
sl@0
   312
//		trace.SetFilter2(EF32TraceUidProxyDrive,1);
sl@0
   313
sl@0
   314
		trace.Close();	
sl@0
   315
		}
sl@0
   316
sl@0
   317
#endif
sl@0
   318
sl@0
   319
//
sl@0
   320
// Load the file system's device driver
sl@0
   321
//
sl@0
   322
	r=User::LoadLogicalDevice(KMediaLddName);
sl@0
   323
	__PRINT1(_L("User::LoadLogicalDevice(KMediaLddName) returns %d"),r);
sl@0
   324
sl@0
   325
	__ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists || r==KErrNotFound,Fault(EMainCreateResources6));
sl@0
   326
	#ifdef __WINS__
sl@0
   327
		// Load media drivers using Win32 functions.  It is not possible to directly
sl@0
   328
		// read the \epoc32\release\wins\udeb directory, and ELOCAL must be mounted
sl@0
   329
		// to access Win32 anyway.
sl@0
   330
sl@0
   331
		_LIT(KMDW1, "MED*.PDD");
sl@0
   332
		TBuf<9> KMDW(KMDW1);					// reserve space for \0
sl@0
   333
sl@0
   334
		TFileName *pfn = new TFileName;
sl@0
   335
		__ASSERT_ALWAYS(pfn != NULL, Fault(EMainScanMediaDriversMem1));
sl@0
   336
		TFileName &fn = *pfn;
sl@0
   337
sl@0
   338
		MapEmulatedFileName(fn, KMDW);
sl@0
   339
		__ASSERT_ALWAYS(fn.Length() < KMaxFileName, Fault(EMainScanMediaDriversLocation));
sl@0
   340
sl@0
   341
		WIN32_FIND_DATA ffd;
sl@0
   342
		HANDLE h = Emulator::FindFirstFile((LPCTSTR)fn.PtrZ(), &ffd); //SL: added cast
sl@0
   343
		BOOL fF = (h != INVALID_HANDLE_VALUE);
sl@0
   344
		while (fF)
sl@0
   345
			{
sl@0
   346
			TPtrC mdNm((const TUint16 *)ffd.cFileName);			// null terminated wchar_t array SL: added cast
sl@0
   347
sl@0
   348
			// NB: parse Win32 file path with EPOC32 functionality.
sl@0
   349
			TParse *pprs = new TParse;
sl@0
   350
			__ASSERT_ALWAYS(pprs != NULL, Fault(EMainScanMediaDriversMem2));
sl@0
   351
			TParse &prs = *pprs;
sl@0
   352
			prs.Set(mdNm, NULL, NULL);
sl@0
   353
			r = User::LoadPhysicalDevice(prs.NameAndExt());
sl@0
   354
			__ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists || r==KErrNotFound,Fault(EMainLoadMediaDriver));
sl@0
   355
			fF = Emulator::FindNextFile(h, &ffd);
sl@0
   356
			delete pprs;
sl@0
   357
			}
sl@0
   358
		FindClose(h);							// Win32 direct
sl@0
   359
sl@0
   360
		delete pfn;
sl@0
   361
	#else
sl@0
   362
		// Load media drivers for EPOC32 using built-in rom file system.
sl@0
   363
		{
sl@0
   364
		RFs fsM;
sl@0
   365
		r = fsM.Connect();
sl@0
   366
		__ASSERT_ALWAYS(r==KErrNone,Fault(EMainScanMediaDriverConnect));
sl@0
   367
sl@0
   368
//#ifdef __EPOC32__
sl@0
   369
		_LIT(KMDSysBinHome, "Z:\\Sys\\Bin\\med*.pdd");
sl@0
   370
//#else
sl@0
   371
//		_LIT(KMDHome, "med*.pdd");
sl@0
   372
//#endif
sl@0
   373
		RDir d;
sl@0
   374
		r = d.Open(fsM, KMDSysBinHome, KEntryAttMaskSupported);
sl@0
   375
		__ASSERT_ALWAYS(r==KErrNone,Fault(EMainScanMediaDriverDirOpen));
sl@0
   376
sl@0
   377
		TBool done = EFalse;
sl@0
   378
		do
sl@0
   379
			{
sl@0
   380
			TEntryArray ea;
sl@0
   381
			r = d.Read(ea);
sl@0
   382
			__ASSERT_ALWAYS(r == KErrNone || r == KErrEof, Fault(EMainScanMediaDriverDirRead));
sl@0
   383
			done = (r == KErrEof);
sl@0
   384
sl@0
   385
			for (TInt i = 0; i < ea.Count(); ++i)
sl@0
   386
				{
sl@0
   387
				const TEntry &e = ea[i];
sl@0
   388
				if (!e.IsDir())
sl@0
   389
					{
sl@0
   390
					TParse *pprs = new TParse;
sl@0
   391
					__ASSERT_ALWAYS(pprs != NULL, Fault(EMainScanMediaDriversMem1));
sl@0
   392
					TParse &prs = *pprs;
sl@0
   393
					prs.Set(e.iName, NULL, NULL);
sl@0
   394
					TPtrC mdName(prs.NameAndExt());
sl@0
   395
					r = User::LoadPhysicalDevice(mdName);
sl@0
   396
					__PRINT1(_L("User::LoadPhysicalDevice(mdName) returns %d"),r);
sl@0
   397
					__ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists || r==KErrNotFound,Fault(EMainLoadMediaDriver));
sl@0
   398
					delete pprs;
sl@0
   399
					}
sl@0
   400
				}
sl@0
   401
			} while (! done);
sl@0
   402
		d.Close();
sl@0
   403
sl@0
   404
		fsM.Close();
sl@0
   405
		}
sl@0
   406
	#endif		// else __WINS__
sl@0
   407
sl@0
   408
#if defined(__WINS__)
sl@0
   409
//#ifndef __DATA_CAGING__	
sl@0
   410
		TheDefaultPath=_L("?:\\");
sl@0
   411
		TheDefaultPath[0] = (TUint8) RFs::GetSystemDriveChar();
sl@0
   412
//#endif
sl@0
   413
#endif
sl@0
   414
sl@0
   415
#if defined(__EPOC32__)
sl@0
   416
	TMachineStartupType reason;
sl@0
   417
	UserHal::StartupReason(reason);
sl@0
   418
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
sl@0
   419
	PrintStartUpReason(reason);
sl@0
   420
#endif
sl@0
   421
	OpenOnDriveZOnly = (reason==EStartupSafeReset);
sl@0
   422
#endif
sl@0
   423
sl@0
   424
//
sl@0
   425
// Now we must load estart from z:
sl@0
   426
//
sl@0
   427
	RProcess eStart;
sl@0
   428
#if defined(__WINS__)
sl@0
   429
	const char* eStartPath = NULL;
sl@0
   430
	UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalStringProperty,(TAny*)"EStart",&eStartPath);
sl@0
   431
	if (eStartPath == NULL)
sl@0
   432
		{
sl@0
   433
		r=eStart.Create(KStartupExeSysBinName,KNullDesC);
sl@0
   434
		}
sl@0
   435
	else
sl@0
   436
		{
sl@0
   437
		TPtrC8 temp((unsigned char *)eStartPath);
sl@0
   438
		TBuf16<KMaxFileName> buf;
sl@0
   439
		buf.Copy(temp);
sl@0
   440
		r=eStart.Create(buf,KNullDesC);
sl@0
   441
		}
sl@0
   442
#else
sl@0
   443
	r=eStart.Create(KStartupExeSysBinName,KNullDesC);
sl@0
   444
#endif
sl@0
   445
sl@0
   446
	if (r!=KErrNone)	// Whoops!
sl@0
   447
		Fault(EMainStartupNoEStart);
sl@0
   448
	eStart.Resume();	// Start the process going
sl@0
   449
	eStart.Close();		// Get rid of our handle
sl@0
   450
#if defined(_LOCKABLE_MEDIA)
sl@0
   451
	// Create a global semaphore for the asynchronous WriteToDisk() threads.
sl@0
   452
	RSemaphore s;
sl@0
   453
	r = s.CreateGlobal(_L("dwsem"), 1);			// only supp 1 thd at a time
sl@0
   454
	__ASSERT_ALWAYS(r == KErrNone, Fault(EMainStartupWriteToDiskSemaphore));
sl@0
   455
#endif
sl@0
   456
sl@0
   457
//
sl@0
   458
// Now we can just exit the startup thread as its no longer needed.
sl@0
   459
//
sl@0
   460
	return(KErrNone);
sl@0
   461
	}
sl@0
   462
sl@0
   463
void commonInitialize()
sl@0
   464
//
sl@0
   465
// Initialization common to all platforms.
sl@0
   466
//
sl@0
   467
	{
sl@0
   468
sl@0
   469
	__PRINT(_L("commonInitialize"));
sl@0
   470
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
sl@0
   471
	ErrorCondition=KErrNone;
sl@0
   472
	ErrorCount=0;
sl@0
   473
	UserHeapAllocFailCount=-1;
sl@0
   474
	KernHeapAllocFailCount=-1;
sl@0
   475
#endif
sl@0
   476
	
sl@0
   477
	TInt r= RequestAllocator::iCacheLock.CreateLocal();
sl@0
   478
	__ASSERT_ALWAYS(r==KErrNone,Fault(EFsCacheLockFailure));
sl@0
   479
	
sl@0
   480
	// initialise the TParse pool lock object
sl@0
   481
	r = TParsePool::Init();
sl@0
   482
	__ASSERT_ALWAYS(r==KErrNone,Fault(EFsParsePoolLockFailure));
sl@0
   483
	
sl@0
   484
	// Get local copies of capability sets
sl@0
   485
	TCapabilitySet caps;
sl@0
   486
	caps.SetAllSupported();
sl@0
   487
	AllCapabilities=*(SCapabilitySet*)&caps;
sl@0
   488
	caps.SetDisabled();
sl@0
   489
	DisabledCapabilities=*(SCapabilitySet*)&caps;
sl@0
   490
sl@0
   491
	FsThreadManager::SetMainThreadId();
sl@0
   492
	r=FsThreadManager::CreateDisconnectThread();
sl@0
   493
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainDisconnectThread));
sl@0
   494
sl@0
   495
	RequestAllocator::Initialise();
sl@0
   496
sl@0
   497
	//
sl@0
   498
	// Install a trap handler
sl@0
   499
	//
sl@0
   500
	CTrapCleanup* trapHandler=CTrapCleanup::New();
sl@0
   501
	__ASSERT_ALWAYS(trapHandler!=NULL,Fault(EMainCreateResources1));
sl@0
   502
sl@0
   503
	TRAP(r,createAllL())
sl@0
   504
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainCreateResources1));
sl@0
   505
	CActiveSchedulerFs::New();
sl@0
   506
	CServerFs::New();
sl@0
   507
	TheKernEventNotifier = CKernEventNotifier::New();
sl@0
   508
    __ASSERT_ALWAYS(TheKernEventNotifier,Fault(EMainCreateResources5));
sl@0
   509
    CActiveSchedulerFs::Add(TheKernEventNotifier);
sl@0
   510
    TheKernEventNotifier->Start();
sl@0
   511
//
sl@0
   512
	__ASSERT_ALWAYS(InitLoader()==KErrNone,Fault(ELdrRestartInit));
sl@0
   513
//
sl@0
   514
	LocalFileSystemInitialized=EFalse;
sl@0
   515
	StartupInitCompleted=EFalse;
sl@0
   516
	RefreshZDriveCache=EFalse;
sl@0
   517
	CompFsMounted=EFalse;
sl@0
   518
	CompFsSync=ETrue;
sl@0
   519
sl@0
   520
	// initialise notification information
sl@0
   521
	FsNotify::Initialise();
sl@0
   522
	// initialise local drive specific information
sl@0
   523
	LocalDrives::Initialise();
sl@0
   524
sl@0
   525
	TRAP(r, FsPluginManager::InitialiseL());
sl@0
   526
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainCreateStartupThread0));
sl@0
   527
sl@0
   528
	RThread t;
sl@0
   529
	r=t.Create(_L("StartupThread"),StartupThread,KDefaultStackSize,KHeapMinSize,KHeapMinSize,NULL);
sl@0
   530
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainCreateStartupThread1));
sl@0
   531
	t.SetPriority(EPriorityLess);
sl@0
   532
sl@0
   533
	CLogon* pL=NULL;
sl@0
   534
	TRAP(r,pL=CLogon::NewL());
sl@0
   535
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainCreateStartupThread2));
sl@0
   536
sl@0
   537
	// NOTE: This function only returns after the startup thread has exited
sl@0
   538
	r=pL->Logon(t);
sl@0
   539
sl@0
   540
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainCreateStartupThread3));
sl@0
   541
	delete pL;
sl@0
   542
sl@0
   543
	// Make a proper process relative handle to the server
sl@0
   544
	r=TheServerThread.Duplicate(TheServerThread);
sl@0
   545
	__ASSERT_ALWAYS(r==KErrNone,Fault(EMainCreateStartupThread4));
sl@0
   546
	ServerThreadAllocator = &User::Heap();
sl@0
   547
	}
sl@0
   548
sl@0
   549
TBool ServerIsRunning()
sl@0
   550
//
sl@0
   551
// Check whether or not the server already exists
sl@0
   552
//
sl@0
   553
	{
sl@0
   554
sl@0
   555
	TFullName serverName;
sl@0
   556
	TFindServer fileServer(KFileServerName);
sl@0
   557
	TInt result=fileServer.Next(serverName);
sl@0
   558
	if (result!=KErrNotFound)
sl@0
   559
		return(ETrue);
sl@0
   560
	return(EFalse);
sl@0
   561
	}
sl@0
   562
sl@0
   563
TInt E32Main()
sl@0
   564
//
sl@0
   565
// The file server.
sl@0
   566
//
sl@0
   567
	{
sl@0
   568
	if (ServerIsRunning())
sl@0
   569
		return(KErrNone);
sl@0
   570
sl@0
   571
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
sl@0
   572
	if (UserSvr::DebugMask() & 0x402)	// KBOOT | KDLL
sl@0
   573
		//DebugReg=KFLDR;
sl@0
   574
		//DebugReg=KFSERV|KFLDR;
sl@0
   575
		DebugReg=KFSERV|KFLDR|KLFFS|KTHRD|KROFS;
sl@0
   576
		
sl@0
   577
//	DebugReg=KFSYS|KFSERV|KFLDR|KLFFS|KTHRD|KCACHE|KROFS|KCOMPFS|KCACHE;
sl@0
   578
//	User::SetDebugMask(0x80004000);
sl@0
   579
sl@0
   580
#endif
sl@0
   581
	__PRINT(_L("FileServer E32Main"));
sl@0
   582
	
sl@0
   583
	UserSvr::FsRegisterThread();
sl@0
   584
	RThread().SetPriority(EPriorityMore);
sl@0
   585
	commonInitialize();
sl@0
   586
	CActiveSchedulerFs::Start();
sl@0
   587
	return(KErrNone);
sl@0
   588
	}
sl@0
   589