Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbootmgr.c
Go to the documentation of this file.
00001 /* 00002 * FreeLoader 00003 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #include <freeldr.h> 00021 00022 ARC_DISK_SIGNATURE reactos_arc_disk_info[32]; // ARC Disk Information 00023 unsigned long reactos_disk_count = 0; 00024 char reactos_arc_hardware_data[HW_MAX_ARC_HEAP_SIZE] = {0}; 00025 char reactos_arc_strings[32][256]; 00026 00027 ULONG GetDefaultOperatingSystem(OperatingSystemItem* OperatingSystemList, ULONG OperatingSystemCount) 00028 { 00029 CHAR DefaultOSText[80]; 00030 PCSTR DefaultOSName; 00031 ULONG_PTR SectionId; 00032 ULONG DefaultOS = 0; 00033 ULONG Idx; 00034 00035 if (!IniOpenSection("FreeLoader", &SectionId)) 00036 { 00037 return 0; 00038 } 00039 00040 DefaultOSName = CmdLineGetDefaultOS(); 00041 if (NULL == DefaultOSName) 00042 { 00043 if (IniReadSettingByName(SectionId, "DefaultOS", DefaultOSText, sizeof(DefaultOSText))) 00044 { 00045 DefaultOSName = DefaultOSText; 00046 } 00047 } 00048 00049 if (NULL != DefaultOSName) 00050 { 00051 for (Idx=0; Idx<OperatingSystemCount; Idx++) 00052 { 00053 if (_stricmp(DefaultOSName, OperatingSystemList[Idx].SystemPartition) == 0) 00054 { 00055 DefaultOS = Idx; 00056 break; 00057 } 00058 } 00059 } 00060 00061 return DefaultOS; 00062 } 00063 00064 LONG GetTimeOut(VOID) 00065 { 00066 CHAR TimeOutText[20]; 00067 LONG TimeOut; 00068 ULONG_PTR SectionId; 00069 00070 TimeOut = CmdLineGetTimeOut(); 00071 if (0 <= TimeOut) 00072 { 00073 return TimeOut; 00074 } 00075 00076 if (!IniOpenSection("FreeLoader", &SectionId)) 00077 { 00078 return -1; 00079 } 00080 00081 if (IniReadSettingByName(SectionId, "TimeOut", TimeOutText, sizeof(TimeOutText))) 00082 { 00083 TimeOut = atoi(TimeOutText); 00084 } 00085 else 00086 { 00087 TimeOut = -1; 00088 } 00089 00090 return TimeOut; 00091 } 00092 00093 BOOLEAN MainBootMenuKeyPressFilter(ULONG KeyPress) 00094 { 00095 if (KeyPress == KEY_F8) 00096 { 00097 DoOptionsMenu(); 00098 00099 return TRUE; 00100 } 00101 00102 // We didn't handle the key 00103 return FALSE; 00104 } 00105 00106 VOID RunLoader(VOID) 00107 { 00108 CHAR SettingValue[80]; 00109 CHAR BootType[80]; 00110 ULONG_PTR SectionId; 00111 ULONG OperatingSystemCount; 00112 OperatingSystemItem* OperatingSystemList; 00113 PCSTR *OperatingSystemDisplayNames; 00114 PCSTR SectionName; 00115 ULONG i; 00116 ULONG DefaultOperatingSystem; 00117 LONG TimeOut; 00118 ULONG SelectedOperatingSystem; 00119 00120 // FIXME: if possible, only detect and register ARC devices... 00121 if (!MachHwDetect()) 00122 { 00123 UiMessageBoxCritical("Error when detecting hardware"); 00124 return; 00125 } 00126 00127 #ifdef _M_IX86 00128 // Load additional SCSI driver (if any) 00129 if (LoadBootDeviceDriver() != ESUCCESS) 00130 { 00131 UiMessageBoxCritical("Unable to load additional boot device driver"); 00132 } 00133 #endif 00134 00135 if (!IniFileInitialize()) 00136 { 00137 UiMessageBoxCritical("Error initializing .ini file"); 00138 return; 00139 } 00140 00141 if (!IniOpenSection("FreeLoader", &SectionId)) 00142 { 00143 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini."); 00144 return; 00145 } 00146 TimeOut = GetTimeOut(); 00147 00148 if (!UiInitialize(TRUE)) 00149 { 00150 UiMessageBoxCritical("Unable to initialize UI."); 00151 return; 00152 } 00153 00154 OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount); 00155 if (!OperatingSystemList) 00156 { 00157 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot."); 00158 goto reboot; 00159 } 00160 00161 if (OperatingSystemCount == 0) 00162 { 00163 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot."); 00164 goto reboot; 00165 } 00166 00167 DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount); 00168 00169 // 00170 // Create list of display names 00171 // 00172 OperatingSystemDisplayNames = MmHeapAlloc(sizeof(PCSTR) * OperatingSystemCount); 00173 if (!OperatingSystemDisplayNames) 00174 { 00175 goto reboot; 00176 } 00177 for (i = 0; i < OperatingSystemCount; i++) 00178 { 00179 OperatingSystemDisplayNames[i] = OperatingSystemList[i].LoadIdentifier; 00180 } 00181 00182 // 00183 // Find all the message box settings and run them 00184 // 00185 UiShowMessageBoxesInSection("FreeLoader"); 00186 00187 for (;;) 00188 { 00189 00190 // Redraw the backdrop 00191 UiDrawBackdrop(); 00192 00193 // Show the operating system list menu 00194 if (!UiDisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem, FALSE, MainBootMenuKeyPressFilter)) 00195 { 00196 UiMessageBox("Press ENTER to reboot."); 00197 goto reboot; 00198 } 00199 00200 TimeOut = -1; 00201 00202 // Try to open the operating system section in the .ini file 00203 SettingValue[0] = ANSI_NULL; 00204 SectionName = OperatingSystemList[SelectedOperatingSystem].SystemPartition; 00205 if (IniOpenSection(SectionName, &SectionId)) 00206 { 00207 // Try to read the boot type 00208 IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType)); 00209 } 00210 else 00211 BootType[0] = ANSI_NULL; 00212 00213 if (BootType[0] == ANSI_NULL && SectionName[0] != ANSI_NULL) 00214 { 00215 // Try to infere boot type value 00216 #ifdef _M_IX86 00217 ULONG FileId; 00218 if (ArcOpen((CHAR*)SectionName, OpenReadOnly, &FileId) == ESUCCESS) 00219 { 00220 ArcClose(FileId); 00221 strcpy(BootType, "BootSector"); 00222 } 00223 else 00224 #endif 00225 { 00226 strcpy(BootType, "Windows"); 00227 } 00228 } 00229 00230 // Get OS setting value 00231 IniOpenSection("Operating Systems", &SectionId); 00232 IniReadSettingByName(SectionId, SectionName, SettingValue, sizeof(SettingValue)); 00233 00234 // Install the drive mapper according to this sections drive mappings 00235 #if defined(_M_IX86) && !defined(_MSC_VER) 00236 DriveMapMapDrivesInSection(SectionName); 00237 #endif 00238 00239 #ifdef FREELDR_REACTOS_SETUP 00240 // WinLdr-style boot 00241 LoadReactOSSetup(); 00242 #elif defined(_M_IX86) 00243 if (_stricmp(BootType, "Windows") == 0) 00244 { 00245 LoadAndBootWindows(SectionName, SettingValue, 0); 00246 } 00247 else if (_stricmp(BootType, "WindowsNT40") == 0) 00248 { 00249 LoadAndBootWindows(SectionName, SettingValue, _WIN32_WINNT_NT4); 00250 } 00251 else if (_stricmp(BootType, "Windows2003") == 0) 00252 { 00253 LoadAndBootWindows(SectionName, SettingValue, _WIN32_WINNT_WS03); 00254 } 00255 else if (_stricmp(BootType, "Linux") == 0) 00256 { 00257 LoadAndBootLinux(SectionName, OperatingSystemDisplayNames[SelectedOperatingSystem]); 00258 } 00259 else if (_stricmp(BootType, "BootSector") == 0) 00260 { 00261 LoadAndBootBootSector(SectionName); 00262 } 00263 else if (_stricmp(BootType, "Partition") == 0) 00264 { 00265 LoadAndBootPartition(SectionName); 00266 } 00267 else if (_stricmp(BootType, "Drive") == 0) 00268 { 00269 LoadAndBootDrive(SectionName); 00270 } 00271 #else 00272 LoadAndBootWindows(SectionName, SettingValue, _WIN32_WINNT_WS03); 00273 #endif 00274 } 00275 00276 reboot: 00277 UiUnInitialize("Rebooting..."); 00278 return; 00279 } Generated on Fri May 25 2012 04:17:11 for ReactOS by
1.7.6.1
|