First public contribution.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // wins\estart\estartmain.cpp
25 #define WIN32_LEAN_AND_MEAN
26 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
28 #pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union
32 _LIT(KLitAddFsFail,"Add fs fail");
33 _LIT(KLitConnectFsFail2,"Connect fs 2 fail");
34 _LIT(KLitNoWS,"No WSERV");
35 _LIT(KStartupModeFail,"Get startup mode failed");
36 _LIT(KLocalFsName,"elocal");
38 class TWinsFSStartup : public TFSStartup
41 virtual TInt StartSystem();
42 virtual TInt DefaultLocalDrive(TInt aLocalDrive);
43 virtual TPtrC LocalDriveMappingFileName();
44 #if !defined(AUTODETECT_DISABLE)
45 virtual TInt GetNextStandardFSInfoEntry(const SFileSystemInfo** anEntry,TInt aPos);
48 void LocalFSInitialisation();
50 TInt GetStartupMode();
53 #if !defined(AUTODETECT_DISABLE)
54 TInt DetectEmulRAM(RLocalDrive ld, TInt cr, TLocalDriveCapsV2& caps)
58 if (caps.iType==EMediaRam)
63 TInt DetectEmul_CF_FAT(RLocalDrive ld, TInt cr, TLocalDriveCapsV2& caps)
67 if (caps.iType!=EMediaHardDisk || !(caps.iDriveAtt & KDriveAttRemovable))
70 return KErrNone; // removable and not ready - assume fat
71 if (cr==KErrNone && PartitionIsFAT(caps.iPartitionType))
76 TInt DetectEmul_CF_FAT32(RLocalDrive ld, TInt cr, TLocalDriveCapsV2& caps)
80 if (caps.iType!=EMediaHardDisk || !(caps.iDriveAtt & KDriveAttRemovable))
83 return KErrNone; // removable and not ready - assume fat
84 if (cr==KErrNone && (PartitionIsFAT32(caps.iPartitionType) || PartitionIsFAT(caps.iPartitionType)) )
91 _LIT(KLocalDriveMappingFileSysBin,"Z:\\SYS\\DATA\\ESTART.TXT");
92 TPtrC TWinsFSStartup::LocalDriveMappingFileName()
94 __ASSERT_ALWAYS(InitCompositeFileSystem()==KErrNone,User::Panic(_L("InitCompositeFileSystem failed."),0));
95 return(KLocalDriveMappingFileSysBin());
98 LOCAL_C void AutoRun()
100 // Ensure that any background initialisation completes before auto-running
102 me.SetPriority(EPriorityLow);
103 const char* autorun = EmulatorAutoRun();
107 const char* cmdline = EmulatorCommandLine();
109 exe.Copy(TPtrC8((const TText8*)autorun));
110 TPtrC8 c((const TText8*)cmdline);
111 HBufC* command = HBufC::New(c.Length());
116 TPtr ptr(command->Des());
119 r = p.Create(exe, *command);
124 me.SetPriority(EPriorityHigh); // ensure we detect termination early
127 User::WaitForRequest(s);
131 Emulator::Escape(); // make sure we don't get suspended while exiting
136 const TInt WinsDefaultLocalDrives[KMaxLocalDrives]=
139 EDriveX, //1 MMC - Slot 0, partition 0
140 KDriveInvalid, //2 MMC - Slot 0, partition 1
141 EDriveT, //3 MMC - Slot 1, partition 0
142 KDriveInvalid, //4 MMC - Slot 1, partition 1
143 EDriveU, //5 NAND - USER DATA
144 EDriveV, //6 NAND - CODE
156 TInt TWinsFSStartup::DefaultLocalDrive(TInt aLocalDrive)
159 return(WinsDefaultLocalDrives[aLocalDrive]);
162 #if !defined(AUTODETECT_DISABLE)
163 const TInt KMaxWinsFSInfoTableEntries=7;
164 LOCAL_D const SFileSystemInfo FileSystems[KMaxWinsFSInfoTableEntries] =
166 {DetectEmulRAM, _S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT},
167 {DetectEmul_CF_FAT32,_S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT},
168 {DetectFtl, _S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT},
169 {DetectRofs, _S("erofs"), _S("rofs"), 0, FS_DISMNT_CORRUPT},
170 {DetectEneaLFFS, _S("elffs"), _S("lffs"), 0, FS_FORMAT_CORRUPT},
171 {DetectIso9660, _S("iso9660"), 0, 0, 0},
172 {DetectNtfs, _S("ntfs"), 0, 0, 0},
175 // additional structure for DetectFtl entry with extension set to "0"
176 LOCAL_D const SFileSystemInfo FileSystemForDetectFtl =
177 {DetectFtl, _S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT};
180 TInt TWinsFSStartup::GetNextStandardFSInfoEntry(const SFileSystemInfo** anEntry,TInt aPos)
182 if (aPos<KMaxWinsFSInfoTableEntries)
184 *anEntry=&FileSystems[aPos];
188 return(KErrNotFound);
192 void TWinsFSStartup::LocalFSInitialisation()
194 // Add and mount local file system
198 DEBUGPRINT("LocalFSInitialisation");
200 // Add local file system
201 TInt r=iFs.AddFileSystem(KLocalFsName);
203 User::Panic(KLitAddFsFail,r);
205 // Close and reopen to make sure the session path is updated
209 User::Panic(KLitConnectFsFail2,r);
212 _LIT(KLitLocalFsName,"Win32");
214 TBuf<4> root=_L("?:\\");
215 for(i=0;i<KMaxDrives-1;++i)
217 r=RFs::DriveToChar(i,drive);
220 root[0]=(TText)drive;
222 if (MapEmulatedFileName(dummy,root)==KErrNone)
224 r=iFs.MountFileSystem(KLitLocalFsName,i);
225 DEBUGPRINT2("MountFileSystem() on drive %d r=%d",i,r);
230 _LIT(KWindowServerRootName1, "EWSRV.EXE");
231 _LIT(KWindowServerRootName2, "WSERV.EXE");
232 _LIT(KSystemStarterName, "z:\\sys\\bin\\SYSSTART.EXE");
233 _LIT(KSystemStateManager, "z:\\sys\\bin\\SYSSTATEMGR.EXE");
234 _LIT(KPropertyError, "RProperty return error");
236 TInt TWinsFSStartup::StartSystem()
238 // Get boot mode with need to access file server
239 TInt r = GetStartupModeFromFile();
240 if (r != KErrNotSupported)
243 User::Panic(KStartupModeFail,r);
244 // Update startup mode property value
245 r = RProperty::Set(KUidSystemCategory, KSystemStartupModeKey, iStartupMode);
247 User::Panic(KPropertyError, r);
250 // Launch system starter and return unless in noGui or textshell mode
251 TBool noSysStart = EFalse;
252 UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalBoolProperty, (TAny*)"_NOSYSSTART", &noSysStart);
254 if (!EmulatorNoGui() && !EmulatorTextShell() && !EmulatorMiniGui() && !noSysStart)
257 r=ws.Create(KSystemStateManager, KNullDesC);
260 r=ws.Create(KSystemStarterName, KNullDesC);
263 TRequestStatus status;
264 ws.Rendezvous(status);
266 User::WaitForRequest(status);
267 // Some system starters may not exit on completion.
268 if (ws.ExitType() != EExitKill && ws.ExitType() != EExitPending)
269 User::Panic(_L("SysStart died"),status.Int());
276 TRequestStatus status;
277 ws.Rendezvous(status);
279 User::WaitForRequest(status);
280 if (ws.ExitType() != EExitKill && ws.ExitType() != EExitPending)
281 User::Panic(_L("SysStart died"),status.Int());
287 // Start system agent 2, continue if executable not found, otherwise panic
289 if (r!=KErrNone && r!=KErrNotFound)
290 User::Panic(_L("Error launching System Agent"),r);
292 // If noGui specifed, then we're done
296 // Attempt to start the appropriate window server
299 if (!EmulatorTextShell() && CreateServer(list,KWindowServerRootName2))
301 if (!CreateServer(list,KWindowServerRootName1))
302 User::Panic(KLitNoWS,KErrNotFound);
307 TInt TWinsFSStartup::GetStartupMode()
309 UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty,
310 (TAny*)"StartupMode", &iStartupMode);
314 GLDEF_C TInt E32Main()
317 TWinsFSStartup fsStart;
320 fsStart.LocalFSInitialisation();
323 fsStart.StartSystem();