#include <freeldr.h>
#include <debug.h>
+DBG_DEFAULT_CHANNEL(INIFILE);
+
/* GLOBALS ********************************************************************/
typedef
VOID
-(*OS_LOADING_METHOD)(IN OperatingSystemItem* OperatingSystem,
- IN USHORT OperatingSystemVersion);
+(*EDIT_OS_ENTRY_PROC)(
+ IN ULONG_PTR SectionId OPTIONAL);
+
+static VOID
+EditCustomBootReactOSSetup(
+ IN ULONG_PTR SectionId OPTIONAL)
+{
+ EditCustomBootReactOS(SectionId, TRUE);
+}
+
+static VOID
+EditCustomBootNTOS(
+ IN ULONG_PTR SectionId OPTIONAL)
+{
+ EditCustomBootReactOS(SectionId, FALSE);
+}
static const struct
{
- PCHAR BootType;
- USHORT OperatingSystemVersion;
- OS_LOADING_METHOD Load;
+ PCSTR BootType;
+ EDIT_OS_ENTRY_PROC EditOsEntry;
+ ARC_ENTRY_POINT OsLoader;
} OSLoadingMethods[] =
{
- {"ReactOSSetup", 0 , LoadReactOSSetup },
+ {"ReactOSSetup", EditCustomBootReactOSSetup, LoadReactOSSetup},
#ifdef _M_IX86
- {"BootSector" , 0 , LoadAndBootBootSector},
- {"Drive" , 0 , LoadAndBootDrive },
- {"Partition" , 0 , LoadAndBootPartition },
+ {"Drive" , EditCustomBootDisk , LoadAndBootDrive },
+ {"Partition" , EditCustomBootPartition , LoadAndBootPartition },
+ {"BootSector" , EditCustomBootSectorFile, LoadAndBootBootSector},
- {"Linux" , 0 , LoadAndBootLinux },
-
- {"Windows" , 0 , LoadAndBootWindows },
- {"WindowsNT40" , _WIN32_WINNT_NT4 , LoadAndBootWindows },
+ {"Linux" , EditCustomBootLinux, LoadAndBootLinux },
+ {"WindowsNT40" , EditCustomBootNTOS , LoadAndBootWindows},
#endif
- {"Windows2003" , _WIN32_WINNT_WS03, LoadAndBootWindows },
+ {"Windows" , EditCustomBootNTOS , LoadAndBootWindows},
+ {"Windows2003" , EditCustomBootNTOS , LoadAndBootWindows},
};
/* FUNCTIONS ******************************************************************/
-VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
+PCHAR*
+BuildArgvForOsLoader(
+ IN PCSTR LoadIdentifier,
+ IN ULONG_PTR SectionId,
+ OUT PULONG pArgc)
{
- ULONG_PTR SectionId;
- PCSTR SectionName = OperatingSystem->SystemPartition;
- CHAR BootType[80];
+ SIZE_T Size;
+ ULONG Count;
ULONG i;
-
- /* Try to open the operating system section in the .ini file */
- if (IniOpenSection(SectionName, &SectionId))
+ ULONG Argc;
+ PCHAR* Argv;
+ PCHAR* Args;
+ PCHAR SettingName, SettingValue;
+
+ /*
+ * Convert the list of key=value options in the given operating system section
+ * into a ARC-compatible argument vector.
+ */
+
+ *pArgc = 0;
+
+ /* Validate the LoadIdentifier (to make tests simpler later) */
+ if (LoadIdentifier && !*LoadIdentifier)
+ LoadIdentifier = NULL;
+
+ /* Count the number of operating systems in the section */
+ Count = IniGetNumSectionItems(SectionId);
+
+ /* The argument vector contains the program name, the LoadIdentifier (optional), and the items in the OS section */
+ Argc = 1 + Count;
+ if (LoadIdentifier)
+ ++Argc;
+
+ /* Calculate the total size needed for the string buffer of the argument vector */
+ Size = 0;
+ /* i == 0: Program name */
+ /* i == 1: LoadIdentifier */
+ if (LoadIdentifier)
{
- /* Try to read the boot type */
- IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
+ Size += (strlen("LoadIdentifier=") + strlen(LoadIdentifier) + 1) * sizeof(CHAR);
}
- else
+ for (i = 0; i < Count; ++i)
{
- BootType[0] = ANSI_NULL;
+ Size += IniGetSectionSettingNameSize(SectionId, i); // Counts also the NULL-terminator, that we transform into the '=' sign separator.
+ Size += IniGetSectionSettingValueSize(SectionId, i); // Counts also the NULL-terminator.
}
+ Size += sizeof(ANSI_NULL); // Final NULL-terminator.
+
+ /* Allocate memory to hold the argument vector: pointers and string buffer */
+ Argv = FrLdrHeapAlloc(Argc * sizeof(PCHAR) + Size, TAG_STRING);
+ if (!Argv)
+ return NULL;
+
+ /* Initialize the argument vector: loop through the section and copy the key=value options */
+ SettingName = (PCHAR)((ULONG_PTR)Argv + (Argc * sizeof(PCHAR)));
+ Args = Argv;
+ /* i == 0: Program name */
+ *Args++ = NULL;
+ /* i == 1: LoadIdentifier */
+ if (LoadIdentifier)
+ {
+ strcpy(SettingName, "LoadIdentifier=");
+ strcat(SettingName, LoadIdentifier);
- if (BootType[0] == ANSI_NULL && SectionName[0] != ANSI_NULL)
+ *Args++ = SettingName;
+ SettingName += (strlen(SettingName) + 1);
+ }
+ for (i = 0; i < Count; ++i)
{
- /* Try to infer the boot type value */
-#ifdef _M_IX86
- ULONG FileId;
- if (ArcOpen((PSTR)SectionName, OpenReadOnly, &FileId) == ESUCCESS)
- {
- ArcClose(FileId);
- strcpy(BootType, "BootSector");
- }
- else
+ Size = IniGetSectionSettingNameSize(SectionId, i);
+ SettingValue = SettingName + Size;
+ IniReadSettingByNumber(SectionId, i,
+ SettingName, Size,
+ SettingValue, IniGetSectionSettingValueSize(SectionId, i));
+ SettingName[Size - 1] = '=';
+
+ *Args++ = SettingName;
+ SettingName += (strlen(SettingName) + 1);
+ }
+
+#if DBG
+ /* Dump the argument vector for debugging */
+ for (i = 0; i < Argc; ++i)
+ {
+ TRACE("Argv[%lu]: '%s'\n", i, Argv[i]);
+ }
#endif
- {
- strcpy(BootType, "Windows");
- }
+
+ *pArgc = Argc;
+ return Argv;
+}
+
+VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
+{
+ ULONG_PTR SectionId;
+ PCSTR SectionName = OperatingSystem->SectionName;
+ ULONG i;
+ ULONG Argc;
+ PCHAR* Argv;
+ CHAR BootType[80];
+
+ /* Try to open the operating system section in the .ini file */
+ if (!IniOpenSection(SectionName, &SectionId))
+ {
+ UiMessageBox("Section [%s] not found in freeldr.ini.", SectionName);
+ return;
}
-#if defined(_M_IX86)
+ /* Try to read the boot type */
+ *BootType = ANSI_NULL;
+ IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
+
+ /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
+ ASSERT(*BootType);
+
+#ifdef _M_IX86
/* Install the drive mapper according to this section drive mappings */
DriveMapMapDrivesInSection(SectionName);
#endif
{
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
{
- OSLoadingMethods[i].Load(OperatingSystem,
- OSLoadingMethods[i].OperatingSystemVersion);
+ Argv = BuildArgvForOsLoader(OperatingSystem->LoadIdentifier, SectionId, &Argc);
+ if (Argv)
+ {
+ OSLoadingMethods[i].OsLoader(Argc, Argv, NULL);
+ FrLdrHeapFree(Argv, TAG_STRING);
+ }
return;
}
}
}
-ULONG GetDefaultOperatingSystem(OperatingSystemItem* OperatingSystemList, ULONG OperatingSystemCount)
+#ifdef HAS_OPTION_MENU_EDIT_CMDLINE
+
+VOID EditOperatingSystemEntry(IN OperatingSystemItem* OperatingSystem)
{
- CHAR DefaultOSText[80];
- PCSTR DefaultOSName;
ULONG_PTR SectionId;
- ULONG DefaultOS = 0;
- ULONG Idx;
-
- if (!IniOpenSection("FreeLoader", &SectionId))
- return 0;
+ PCSTR SectionName = OperatingSystem->SectionName;
+ ULONG i;
+ CHAR BootType[80];
- DefaultOSName = CmdLineGetDefaultOS();
- if (DefaultOSName == NULL)
+ /* Try to open the operating system section in the .ini file */
+ if (!IniOpenSection(SectionName, &SectionId))
{
- if (IniReadSettingByName(SectionId, "DefaultOS", DefaultOSText, sizeof(DefaultOSText)))
- {
- DefaultOSName = DefaultOSText;
- }
+ UiMessageBox("Section [%s] not found in freeldr.ini.", SectionName);
+ return;
}
- if (DefaultOSName != NULL)
+ /* Try to read the boot type */
+ *BootType = ANSI_NULL;
+ IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
+
+ /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
+ ASSERT(*BootType);
+
+ /* Loop through the OS loading method table and find a suitable OS entry editor */
+ for (i = 0; i < sizeof(OSLoadingMethods) / sizeof(OSLoadingMethods[0]); ++i)
{
- for (Idx = 0; Idx < OperatingSystemCount; Idx++)
+ if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
{
- if (_stricmp(DefaultOSName, OperatingSystemList[Idx].SystemPartition) == 0)
- {
- DefaultOS = Idx;
- break;
- }
+ OSLoadingMethods[i].EditOsEntry(SectionId);
+ return;
}
}
-
- return DefaultOS;
}
+#endif // HAS_OPTION_MENU_EDIT_CMDLINE
+
LONG GetTimeOut(VOID)
{
CHAR TimeOutText[20];
return TimeOut;
}
-BOOLEAN MainBootMenuKeyPressFilter(ULONG KeyPress)
+BOOLEAN
+MainBootMenuKeyPressFilter(
+ IN ULONG KeyPress,
+ IN ULONG SelectedMenuItem,
+ IN PVOID Context OPTIONAL)
{
- if (KeyPress == KEY_F8)
+ switch (KeyPress)
{
- DoOptionsMenu();
+ case KEY_F8:
+ DoOptionsMenu(&((OperatingSystemItem*)Context)[SelectedMenuItem]);
return TRUE;
- }
- /* We didn't handle the key */
- return FALSE;
+#ifdef HAS_OPTION_MENU_EDIT_CMDLINE
+ case KEY_F10:
+ EditOperatingSystemEntry(&((OperatingSystemItem*)Context)[SelectedMenuItem]);
+ return TRUE;
+#endif
+
+ default:
+ /* We didn't handle the key */
+ return FALSE;
+ }
}
VOID RunLoader(VOID)
{
ULONG_PTR SectionId;
+ LONG TimeOut;
ULONG OperatingSystemCount;
OperatingSystemItem* OperatingSystemList;
PCSTR* OperatingSystemDisplayNames;
ULONG DefaultOperatingSystem;
- LONG TimeOut;
ULONG SelectedOperatingSystem;
ULONG i;
return;
}
- OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount);
+ OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount,
+ &DefaultOperatingSystem);
if (!OperatingSystemList)
{
UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
goto Reboot;
}
-
if (OperatingSystemCount == 0)
{
UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
goto Reboot;
}
- DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount);
-
/* Create list of display names */
OperatingSystemDisplayNames = FrLdrTempAlloc(sizeof(PCSTR) * OperatingSystemCount, 'mNSO');
if (!OperatingSystemDisplayNames)
TimeOut,
&SelectedOperatingSystem,
FALSE,
- MainBootMenuKeyPressFilter))
+ MainBootMenuKeyPressFilter,
+ OperatingSystemList))
{
UiMessageBox("Press ENTER to reboot.");
goto Reboot;