mirror of
https://github.com/reactos/reactos.git
synced 2024-06-24 06:51:47 +00:00
bd451f240f
CORE-9023 FIXES: ====== - Fix parsing of the multiboot options string. NOTE: They are not yet treated in a case-insensitive manner! - Fix a bug in ArcOpen() so that it correctly skips the first path separator (after the adapter-controller-peripheral ARC descriptors). The path separator can be either a backslash or a slash (both are allowed according to the specs); they were also already handled correctly in other parts of the code. - Fix DissectArcPath() so as to: * **OPTIONALLY** (and not mandatorily!) return the path part that follows the ARC adapter-controller-peripheral elements in the ARC path; * make it correctly handle the (yes, optional!!) partition() part in the ARC path, for the multi(x)disk(y)rdisk(z) cases. ENHANCEMENTS: ============= - Directly retrieve the default OS entry as we enumerate them and build their list (i.e. merge the GetDefaultOperatingSystem() helper within InitOperatingSystemList()). - Directly use the opened 'FreeLoader' INI section via its ID in the different functions that need it. - Make the custom-boot and linux loaders honour the boot options they are supposed to support (see FREELDR.INI documentation / template). This includes the 'BootDrive' and 'BootPartition' (alternatively the ARC 'BootPath'). This also allows them to take into account the user-specified choices in the FreeLdr custom-boot editors. - Modify the FreeLdr custom-boot editors so as to correctly honour the priorities of the boot options as specified in the FREELDR.INI documentation / template. - Use stack trick (union of structs) to reduce stack usage in the FreeLdr custom-boot editors, because there are strings buffers that are used in an alternate manner. - Extract out from the editors the LoadOperatingSystem() calls, and move it back into OptionMenuCustomBoot(), so that when this latter function is called there is no risk of having a stack almost full. - When building the ARC-compatible argument vector for the loaders, add the mandatory "SystemPartition" path. This allows the loaders to NOT call the machine-specific MachDiskGetBootPath() later on (this data is indeed passed to them by the boot manager part of FreeLdr). - Improve the FsOpenFile() helper so as to make it: * return an adequate ARC_STATUS instead of a mere uninformative BOOLEAN; * take open options, as well as a default path (optional) that would be prepended to the file name in case the latter is a relative one. - Make RamDiskLoadVirtualFile() return an actual descriptive ARC_STATUS value, and make it take an optional default path (same usage as the one in FsOpenFile() ). + Remove useless NTAPI . - UiInitialize() and TuiTextToColor(), TuiTextToFillStyle(): load or convert named settings into corresponding values using setting table and a tight for-loop, instead of duplicating 10x the same parameter reading logic. - UiInitialize(): Open the "Display" INI section just once. Remove usage of DisplayModeText[] buffer. - UiShowMessageBoxesInSection() and UiShowMessageBoxesInArgv(): reduce code indentation level. ENHANCEMENTS for NT OS loader: ============================== - Don't use MachDiskGetBootPath() but use instead the "SystemPartition" value passed via the ARC argument vector by the boot manager (+ validation checks). Use it as the "default path" when calling FsOpenFile() or loading the ramdisk. - Honour the FreeLdr-specific "Hal=" and "Kernel=" options by converting them into NT standard "/HAL=" and "/KERNEL=" options in the boot command line. Note that if the latter ones are already present on the standard "Options=" option line, they would take precedence over those passed via the separate "Hal=" and "Kernel=" FreeLdr-specific options. Also add some documentation links to Geoff Chappell's website about how the default HAL and KERNEL names are chosen depending on the detected underlying platform on which the NT OS loader is running.
297 lines
10 KiB
C
297 lines
10 KiB
C
/*
|
|
* FreeLoader
|
|
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
#include <freeldr.h>
|
|
|
|
#include <debug.h>
|
|
DBG_DEFAULT_CHANNEL(INIFILE);
|
|
|
|
#define TAG_OS_ITEM 'tISO'
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
static PCSTR CopyString(PCSTR Source)
|
|
{
|
|
PSTR Dest;
|
|
|
|
if (!Source)
|
|
return NULL;
|
|
|
|
Dest = FrLdrHeapAlloc(strlen(Source) + 1, TAG_STRING);
|
|
if (Dest)
|
|
strcpy(Dest, Source);
|
|
|
|
return Dest;
|
|
}
|
|
|
|
OperatingSystemItem*
|
|
InitOperatingSystemList(
|
|
IN ULONG_PTR FrLdrSectionId,
|
|
OUT PULONG OperatingSystemCount,
|
|
OUT PULONG DefaultOperatingSystem)
|
|
{
|
|
ULONG DefaultOS = 0;
|
|
PCSTR DefaultOSName = NULL;
|
|
CHAR DefaultOSText[80];
|
|
|
|
OperatingSystemItem* Items;
|
|
ULONG Count;
|
|
ULONG i;
|
|
ULONG_PTR OsSectionId, SectionId;
|
|
PCHAR TitleStart, TitleEnd;
|
|
PCSTR OsLoadOptions;
|
|
BOOLEAN HadSection;
|
|
BOOLEAN HadNoBootType;
|
|
CHAR SettingName[260];
|
|
CHAR SettingValue[260];
|
|
CHAR BootType[80];
|
|
CHAR TempBuffer[sizeof(SettingValue)/sizeof(CHAR)];
|
|
|
|
/* Open the [Operating Systems] section */
|
|
if (!IniOpenSection("Operating Systems", &OsSectionId))
|
|
return NULL;
|
|
|
|
/* Count the number of operating systems in the section */
|
|
Count = IniGetNumSectionItems(OsSectionId);
|
|
|
|
/* Allocate memory to hold operating system lists */
|
|
Items = FrLdrHeapAlloc(Count * sizeof(OperatingSystemItem), TAG_OS_ITEM);
|
|
if (!Items)
|
|
return NULL;
|
|
|
|
/* Retrieve which OS is the default one */
|
|
DefaultOSName = CmdLineGetDefaultOS();
|
|
if (!DefaultOSName || !*DefaultOSName)
|
|
{
|
|
if ((FrLdrSectionId != 0) &&
|
|
IniReadSettingByName(FrLdrSectionId, "DefaultOS", DefaultOSText, sizeof(DefaultOSText)))
|
|
{
|
|
DefaultOSName = DefaultOSText;
|
|
}
|
|
}
|
|
|
|
/* Now loop through the operating system section and load each item */
|
|
for (i = 0; i < Count; ++i)
|
|
{
|
|
IniReadSettingByNumber(OsSectionId, i,
|
|
SettingName, sizeof(SettingName),
|
|
SettingValue, sizeof(SettingValue));
|
|
if (!*SettingName)
|
|
{
|
|
ERR("Invalid OS entry %lu, skipping.\n", i);
|
|
continue;
|
|
}
|
|
|
|
/* Retrieve the start and end of the title */
|
|
TitleStart = SettingValue;
|
|
/* Trim any leading whitespace and quotes */
|
|
while (*TitleStart == ' ' || *TitleStart == '\t' || *TitleStart == '"')
|
|
++TitleStart;
|
|
TitleEnd = TitleStart;
|
|
/* Go up to the first last quote */
|
|
while (*TitleEnd != ANSI_NULL && *TitleEnd != '"')
|
|
++TitleEnd;
|
|
|
|
/* NULL-terminate the title */
|
|
if (*TitleEnd)
|
|
*TitleEnd++ = ANSI_NULL; // Skip the quote too.
|
|
|
|
/* Retrieve the options after the quoted title */
|
|
if (*TitleEnd)
|
|
{
|
|
/* Trim any trailing whitespace and quotes */
|
|
while (*TitleEnd == ' ' || *TitleEnd == '\t' || *TitleEnd == '"')
|
|
++TitleEnd;
|
|
}
|
|
OsLoadOptions = (*TitleEnd ? TitleEnd : NULL);
|
|
|
|
// TRACE("\n"
|
|
// "SettingName = '%s'\n"
|
|
// "TitleStart = '%s'\n"
|
|
// "OsLoadOptions = '%s'\n",
|
|
// SettingName, TitleStart, OsLoadOptions);
|
|
|
|
/* Find the default OS item while we haven't got one */
|
|
if (DefaultOSName && _stricmp(DefaultOSName, SettingName) == 0)
|
|
{
|
|
DefaultOS = i;
|
|
DefaultOSName = NULL; // We have found the first one, don't search for others.
|
|
}
|
|
|
|
/*
|
|
* Determine whether this is a legacy operating system entry of the form:
|
|
*
|
|
* [Operating Systems]
|
|
* ArcOsLoadPartition="LoadIdentifier" /List /of /Options
|
|
*
|
|
* and if so, convert it into a new operating system INI entry:
|
|
*
|
|
* [Operating Systems]
|
|
* SectionIdentifier="LoadIdentifier"
|
|
*
|
|
* [SectionIdentifier]
|
|
* BootType=...
|
|
* SystemPath=ArcOsLoadPartition
|
|
* Options=/List /of /Options
|
|
*
|
|
* The "BootType" value is heuristically determined from the form of
|
|
* the ArcOsLoadPartition: if this is an ARC path, the "BootType" value
|
|
* is "Windows", otherwise if this is a DOS path the "BootType" value
|
|
* is "BootSector". This ensures backwards-compatibility with NTLDR.
|
|
*/
|
|
|
|
/* Try to open the operating system section in the .ini file */
|
|
SectionId = 0;
|
|
HadSection = IniOpenSection(SettingName, &SectionId);
|
|
if (HadSection)
|
|
{
|
|
/* This is a new OS entry: try to read the boot type */
|
|
IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
|
|
}
|
|
else
|
|
{
|
|
/* This is a legacy OS entry: no explicit BootType specified, we will infer one */
|
|
*BootType = ANSI_NULL;
|
|
}
|
|
|
|
/* Check whether we have got a BootType value; if not, try to infer one */
|
|
HadNoBootType = (*BootType == ANSI_NULL);
|
|
if (HadNoBootType)
|
|
{
|
|
#ifdef _M_IX86
|
|
ULONG FileId;
|
|
if (ArcOpen(SettingName, OpenReadOnly, &FileId) == ESUCCESS)
|
|
{
|
|
ArcClose(FileId);
|
|
strcpy(BootType, "BootSector");
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
strcpy(BootType, "Windows");
|
|
}
|
|
}
|
|
|
|
/* This is a legacy OS entry: convert it into a new OS entry */
|
|
if (!HadSection)
|
|
{
|
|
TIMEINFO* TimeInfo;
|
|
|
|
/* Save the system path from the original SettingName (overwritten below) */
|
|
RtlStringCbCopyA(TempBuffer, sizeof(TempBuffer), SettingName);
|
|
|
|
/* Generate a unique section name */
|
|
TimeInfo = ArcGetTime();
|
|
if (_stricmp(BootType, "BootSector") == 0)
|
|
{
|
|
RtlStringCbPrintfA(SettingName, sizeof(SettingName),
|
|
"BootSectorFile%u%u%u%u%u%u",
|
|
TimeInfo->Year, TimeInfo->Day, TimeInfo->Month,
|
|
TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
|
|
}
|
|
else if (_stricmp(BootType, "Windows") == 0)
|
|
{
|
|
RtlStringCbPrintfA(SettingName, sizeof(SettingName),
|
|
"Windows%u%u%u%u%u%u",
|
|
TimeInfo->Year, TimeInfo->Day, TimeInfo->Month,
|
|
TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
|
|
}
|
|
else
|
|
{
|
|
ASSERT(FALSE);
|
|
}
|
|
|
|
/* Add the section */
|
|
if (!IniAddSection(SettingName, &SectionId))
|
|
{
|
|
ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
|
|
continue;
|
|
}
|
|
|
|
/* Add the system path */
|
|
if (_stricmp(BootType, "BootSector") == 0)
|
|
{
|
|
if (!IniAddSettingValueToSection(SectionId, "BootSectorFile", TempBuffer))
|
|
{
|
|
ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
|
|
continue;
|
|
}
|
|
}
|
|
else if (_stricmp(BootType, "Windows") == 0)
|
|
{
|
|
if (!IniAddSettingValueToSection(SectionId, "SystemPath", TempBuffer))
|
|
{
|
|
ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
|
|
continue;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ASSERT(FALSE);
|
|
}
|
|
|
|
/* Add the OS options */
|
|
if (OsLoadOptions && !IniAddSettingValueToSection(SectionId, "Options", OsLoadOptions))
|
|
{
|
|
ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
/* Add or modify the BootType if needed */
|
|
if (HadNoBootType && !IniModifySettingValue(SectionId, "BootType", BootType))
|
|
{
|
|
ERR("Could not fixup the BootType entry for OS '%s', ignoring.\n", SettingName);
|
|
}
|
|
|
|
/*
|
|
* If this is a new OS entry, but some options were given appended to
|
|
* the OS entry item, append them instead to the "Options=" value.
|
|
*/
|
|
if (HadSection && OsLoadOptions && *OsLoadOptions)
|
|
{
|
|
/* Read the original "Options=" value */
|
|
*TempBuffer = ANSI_NULL;
|
|
if (!IniReadSettingByName(SectionId, "Options", TempBuffer, sizeof(TempBuffer)))
|
|
TRACE("No 'Options' value found for OS '%s', ignoring.\n", SettingName);
|
|
|
|
/* Concatenate the options together */
|
|
RtlStringCbCatA(TempBuffer, sizeof(TempBuffer), " ");
|
|
RtlStringCbCatA(TempBuffer, sizeof(TempBuffer), OsLoadOptions);
|
|
|
|
/* Save them */
|
|
if (!IniModifySettingValue(SectionId, "Options", TempBuffer))
|
|
ERR("Could not modify the options for OS '%s', ignoring.\n", SettingName);
|
|
}
|
|
|
|
/* Copy the OS section ID and its identifier */
|
|
Items[i].SectionId = SectionId;
|
|
Items[i].LoadIdentifier = CopyString(TitleStart);
|
|
// TRACE("We did Items[%lu]: SectionName = '%s' (SectionId = 0x%p), LoadIdentifier = '%s'\n",
|
|
// i, SettingName, Items[i].SectionId, Items[i].LoadIdentifier);
|
|
}
|
|
|
|
/* Return success */
|
|
*OperatingSystemCount = Count;
|
|
*DefaultOperatingSystem = DefaultOS;
|
|
return Items;
|
|
}
|