ReactOS  r76032
bootmgr.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for bootmgr.c:

Go to the source code of this file.

Typedefs

typedef VOID(* OS_LOADING_METHOD )(IN OperatingSystemItem *OperatingSystem, IN USHORT OperatingSystemVersion)
 

Functions

VOID LoadOperatingSystem (IN OperatingSystemItem *OperatingSystem)
 
ULONG GetDefaultOperatingSystem (OperatingSystemItem *OperatingSystemList, ULONG OperatingSystemCount)
 
LONG GetTimeOut (VOID)
 
BOOLEAN MainBootMenuKeyPressFilter (ULONG KeyPress)
 
VOID RunLoader (VOID)
 

Variables

struct {
   CHAR   BootType [80]
 
   USHORT   OperatingSystemVersion
 
   OS_LOADING_METHOD   Load
 
OSLoadingMethods []
 

Typedef Documentation

typedef VOID(* OS_LOADING_METHOD)(IN OperatingSystemItem *OperatingSystem, IN USHORT OperatingSystemVersion)

Definition at line 29 of file bootmgr.c.

Function Documentation

ULONG GetDefaultOperatingSystem ( OperatingSystemItem OperatingSystemList,
ULONG  OperatingSystemCount 
)

Definition at line 108 of file bootmgr.c.

Referenced by RunLoader().

109 {
110  CHAR DefaultOSText[80];
111  PCSTR DefaultOSName;
112  ULONG_PTR SectionId;
113  ULONG DefaultOS = 0;
114  ULONG Idx;
115 
116  if (!IniOpenSection("FreeLoader", &SectionId))
117  return 0;
118 
119  DefaultOSName = CmdLineGetDefaultOS();
120  if (DefaultOSName == NULL)
121  {
122  if (IniReadSettingByName(SectionId, "DefaultOS", DefaultOSText, sizeof(DefaultOSText)))
123  {
124  DefaultOSName = DefaultOSText;
125  }
126  }
127 
128  if (DefaultOSName != NULL)
129  {
130  for (Idx = 0; Idx < OperatingSystemCount; Idx++)
131  {
132  if (_stricmp(DefaultOSName, OperatingSystemList[Idx].SystemPartition) == 0)
133  {
134  DefaultOS = Idx;
135  break;
136  }
137  }
138  }
139 
140  return DefaultOS;
141 }
const char * PCSTR
Definition: typedefs.h:51
char CHAR
Definition: xmlstorage.h:175
#define _stricmp
Definition: cat.c:22
uint32_t ULONG_PTR
Definition: typedefs.h:63
PCCH CmdLineGetDefaultOS(VOID)
Definition: cmdline.c:131
smooth NULL
Definition: ftsmooth.c:557
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:147
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
unsigned int ULONG
Definition: retypes.h:1
LONG GetTimeOut ( VOID  )

Definition at line 143 of file bootmgr.c.

Referenced by RunLoader().

144 {
145  CHAR TimeOutText[20];
146  LONG TimeOut;
147  ULONG_PTR SectionId;
148 
149  TimeOut = CmdLineGetTimeOut();
150  if (TimeOut >= 0)
151  return TimeOut;
152 
153  if (!IniOpenSection("FreeLoader", &SectionId))
154  return -1;
155 
156  if (IniReadSettingByName(SectionId, "TimeOut", TimeOutText, sizeof(TimeOutText)))
157  TimeOut = atoi(TimeOutText);
158  else
159  TimeOut = -1;
160 
161  return TimeOut;
162 }
LONG CmdLineGetTimeOut(VOID)
Definition: cmdline.c:137
char CHAR
Definition: xmlstorage.h:175
uint32_t ULONG_PTR
Definition: typedefs.h:63
long LONG
Definition: pedump.c:60
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:147
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
VOID LoadOperatingSystem ( IN OperatingSystemItem OperatingSystem)

Definition at line 56 of file bootmgr.c.

Referenced by OptionMenuCustomBootReactOS(), and RunLoader().

57 {
58  ULONG_PTR SectionId;
59  PCSTR SectionName = OperatingSystem->SystemPartition;
60  CHAR BootType[80];
61  ULONG i;
62 
63  /* Try to open the operating system section in the .ini file */
64  if (IniOpenSection(SectionName, &SectionId))
65  {
66  /* Try to read the boot type */
67  IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
68  }
69  else
70  {
71  BootType[0] = ANSI_NULL;
72  }
73 
74  if (BootType[0] == ANSI_NULL && SectionName[0] != ANSI_NULL)
75  {
76  /* Try to infer the boot type value */
77 #ifdef _M_IX86
78  ULONG FileId;
79  if (ArcOpen((PSTR)SectionName, OpenReadOnly, &FileId) == ESUCCESS)
80  {
81  ArcClose(FileId);
82  strcpy(BootType, "BootSector");
83  }
84  else
85 #endif
86  {
87  strcpy(BootType, "Windows");
88  }
89  }
90 
91  /* Install the drive mapper according to this section drive mappings */
92 #if defined(_M_IX86) && !defined(_MSC_VER)
93  DriveMapMapDrivesInSection(SectionName);
94 #endif
95 
96  /* Loop through the OS loading method table and find a suitable OS to boot */
97  for (i = 0; i < sizeof(OSLoadingMethods) / sizeof(OSLoadingMethods[0]); ++i)
98  {
99  if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
100  {
101  OSLoadingMethods[i].Load(OperatingSystem,
103  return;
104  }
105  }
106 }
Definition: arc.h:32
const char * PCSTR
Definition: typedefs.h:51
char CHAR
Definition: xmlstorage.h:175
#define _stricmp
Definition: cat.c:22
CHAR BootType[80]
Definition: bootmgr.c:34
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define ANSI_NULL
VOID DriveMapMapDrivesInSection(PCSTR SectionName)
Definition: drivemap.c:31
USHORT OperatingSystemVersion
Definition: bootmgr.c:35
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:147
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
signed char * PSTR
Definition: retypes.h:7
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:218
struct @147 OSLoadingMethods[]
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:58
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN MainBootMenuKeyPressFilter ( ULONG  KeyPress)

Definition at line 164 of file bootmgr.c.

Referenced by RunLoader().

165 {
166  if (KeyPress == KEY_F8)
167  {
168  DoOptionsMenu();
169  return TRUE;
170  }
171 
172  /* We didn't handle the key */
173  return FALSE;
174 }
#define TRUE
Definition: types.h:120
VOID DoOptionsMenu(VOID)
Definition: options.c:90
#define KEY_F8
Definition: keycodes.h:43
#define FALSE
Definition: types.h:117
VOID RunLoader ( VOID  )

Definition at line 176 of file bootmgr.c.

Referenced by BootMain().

177 {
178  ULONG_PTR SectionId;
179  ULONG OperatingSystemCount;
180  OperatingSystemItem* OperatingSystemList;
181  PCSTR* OperatingSystemDisplayNames;
182  ULONG DefaultOperatingSystem;
183  LONG TimeOut;
184  ULONG SelectedOperatingSystem;
185  ULONG i;
186 
188  {
189  UiMessageBoxCritical("Error when detecting hardware.");
190  return;
191  }
192 
193 #ifdef _M_IX86
194  /* Load additional SCSI driver (if any) */
196  {
197  UiMessageBoxCritical("Unable to load additional boot device drivers.");
198  }
199 #endif
200 
201  if (!IniFileInitialize())
202  {
203  UiMessageBoxCritical("Error initializing .ini file.");
204  return;
205  }
206 
207  /* Debugger main initialization */
208  DebugInit(TRUE);
209 
210  if (!IniOpenSection("FreeLoader", &SectionId))
211  {
212  UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
213  return;
214  }
215 
216  TimeOut = GetTimeOut();
217 
218  /* UI main initialization */
219  if (!UiInitialize(TRUE))
220  {
221  UiMessageBoxCritical("Unable to initialize UI.");
222  return;
223  }
224 
225  OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount);
226  if (!OperatingSystemList)
227  {
228  UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
229  goto Reboot;
230  }
231 
232  if (OperatingSystemCount == 0)
233  {
234  UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
235  goto Reboot;
236  }
237 
238  DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount);
239 
240  /* Create list of display names */
241  OperatingSystemDisplayNames = FrLdrTempAlloc(sizeof(PCSTR) * OperatingSystemCount, 'mNSO');
242  if (!OperatingSystemDisplayNames)
243  goto Reboot;
244 
245  for (i = 0; i < OperatingSystemCount; i++)
246  {
247  OperatingSystemDisplayNames[i] = OperatingSystemList[i].LoadIdentifier;
248  }
249 
250  /* Find all the message box settings and run them */
251  UiShowMessageBoxesInSection("FreeLoader");
252 
253  for (;;)
254  {
255  /* Redraw the backdrop */
256  UiDrawBackdrop();
257 
258  /* Show the operating system list menu */
259  if (!UiDisplayMenu("Please select the operating system to start:",
260  "For troubleshooting and advanced startup options for "
261  "ReactOS, press F8.",
262  TRUE,
263  OperatingSystemDisplayNames,
264  OperatingSystemCount,
265  DefaultOperatingSystem,
266  TimeOut,
267  &SelectedOperatingSystem,
268  FALSE,
270  {
271  UiMessageBox("Press ENTER to reboot.");
272  goto Reboot;
273  }
274 
275  TimeOut = -1;
276 
277  /* Load the chosen operating system */
278  LoadOperatingSystem(&OperatingSystemList[SelectedOperatingSystem]);
279  }
280 
281 Reboot:
282  UiUnInitialize("Rebooting...");
283  return;
284 }
#define DebugInit(init)
Definition: debug.h:116
#define TRUE
Definition: types.h:120
OperatingSystemItem * InitOperatingSystemList(ULONG *OperatingSystemCountPointer)
Definition: oslist.c:43
Definition: arc.h:32
BOOLEAN UiInitialize(BOOLEAN ShowGui)
Definition: ui.c:84
BOOLEAN MainBootMenuKeyPressFilter(ULONG KeyPress)
Definition: bootmgr.c:164
const char * PCSTR
Definition: typedefs.h:51
ULONG LoadBootDeviceDriver(VOID)
Definition: scsiport.c:1592
VOID UiShowMessageBoxesInSection(PCSTR SectionName)
Definition: ui.c:383
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE PVOID FrLdrTempAlloc(ULONG Size, ULONG Tag)
Definition: mm.h:178
#define MachInitializeBootDevices()
Definition: machine.h:127
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
Definition: bl.h:816
ULONG GetDefaultOperatingSystem(OperatingSystemItem *OperatingSystemList, ULONG OperatingSystemCount)
Definition: bootmgr.c:108
BOOLEAN UiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG *SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
Definition: ui.c:459
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
VOID UiUnInitialize(PCSTR BootText)
Definition: ui.c:232
VOID UiDrawBackdrop(VOID)
Definition: ui.c:241
LONG GetTimeOut(VOID)
Definition: bootmgr.c:143
BOOLEAN IniFileInitialize(VOID)
Definition: ini_init.c:38
unsigned int ULONG
Definition: retypes.h:1
VOID LoadOperatingSystem(IN OperatingSystemItem *OperatingSystem)
Definition: bootmgr.c:56
VOID UiMessageBoxCritical(PCSTR MessageText)
Definition: ui.c:358

Variable Documentation

CHAR BootType[80]

Definition at line 34 of file bootmgr.c.

Referenced by LoadOperatingSystem().

USHORT OperatingSystemVersion

Definition at line 35 of file bootmgr.c.

Referenced by LoadOperatingSystem().

struct { ... } OSLoadingMethods[]
Initial value:
=
{
{"ReactOSSetup", 0 , LoadReactOSSetup },
}
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
VOID LoadAndBootWindows(IN OperatingSystemItem *OperatingSystem, IN USHORT OperatingSystemVersion)
Definition: winldr.c:649
VOID LoadReactOSSetup(IN OperatingSystemItem *OperatingSystem, IN USHORT OperatingSystemVersion)
Definition: setupldr.c:137

Referenced by LoadOperatingSystem().