[FREELDR] Minor code improvements + 1 bug-fix.

- "FrldrBootPath" -> "FrLdrBootPath";
- Get rid of GetFreeLoaderVersionString() and use FrLdrVersionString
  directly instead;
- Rephrase some comments;
- Use RTL_NUMBER_OF();
- Reduce indent level in LoadOperatingSystem() and EditOperatingSystemEntry().

Bug fix:
- Fix DissectArcPath() for "ramdisk(0)" case.
This commit is contained in:
Hermès Bélusca-Maïto 2019-09-17 22:24:47 +02:00
parent 86c94e7858
commit fc29a6c41c
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
15 changed files with 68 additions and 92 deletions

View file

@ -81,7 +81,6 @@ list(APPEND FREELDR_BOOTMGR_SOURCE
miscboot.c miscboot.c
options.c options.c
oslist.c oslist.c
version.c
ui/directui.c ui/directui.c
ui/gui.c ui/gui.c
ui/minitui.c ui/minitui.c

View file

@ -139,7 +139,7 @@ ArmInitializeBootDevices(VOID)
return FALSE; return FALSE;
/* On ARM platforms, the loader is always in RAM */ /* On ARM platforms, the loader is always in RAM */
strcpy(FrldrBootPath, "ramdisk(0)"); strcpy(FrLdrBootPath, "ramdisk(0)");
return TRUE; return TRUE;
} }

View file

@ -378,32 +378,32 @@ DiskIsDriveRemovable(UCHAR DriveNumber)
static BOOLEAN static BOOLEAN
DiskGetBootPath(BOOLEAN IsPxe) DiskGetBootPath(BOOLEAN IsPxe)
{ {
if (*FrldrBootPath) if (*FrLdrBootPath)
return TRUE; return TRUE;
// FIXME! FIXME! Do this in some drive recognition procedure!!!! // FIXME! FIXME! Do this in some drive recognition procedure!!!!
if (IsPxe) if (IsPxe)
{ {
RtlStringCbCopyA(FrldrBootPath, sizeof(FrldrBootPath), "net(0)"); RtlStringCbCopyA(FrLdrBootPath, sizeof(FrLdrBootPath), "net(0)");
} }
else else
/* 0x49 is our magic ramdisk drive, so try to detect it first */ /* 0x49 is our magic ramdisk drive, so try to detect it first */
if (FrldrBootDrive == 0x49) if (FrldrBootDrive == 0x49)
{ {
/* This is the ramdisk. See ArmInitializeBootDevices() too... */ /* This is the ramdisk. See ArmInitializeBootDevices() too... */
// RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath), "ramdisk(%u)", 0); // RtlStringCbPrintfA(FrLdrBootPath, sizeof(FrLdrBootPath), "ramdisk(%u)", 0);
RtlStringCbCopyA(FrldrBootPath, sizeof(FrldrBootPath), "ramdisk(0)"); RtlStringCbCopyA(FrLdrBootPath, sizeof(FrLdrBootPath), "ramdisk(0)");
} }
else if (FrldrBootDrive < 0x80) else if (FrldrBootDrive < 0x80)
{ {
/* This is a floppy */ /* This is a floppy */
RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath), RtlStringCbPrintfA(FrLdrBootPath, sizeof(FrLdrBootPath),
"multi(0)disk(0)fdisk(%u)", FrldrBootDrive); "multi(0)disk(0)fdisk(%u)", FrldrBootDrive);
} }
else if (FrldrBootPartition == 0xFF) else if (FrldrBootPartition == 0xFF)
{ {
/* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */ /* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */
RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath), RtlStringCbPrintfA(FrLdrBootPath, sizeof(FrLdrBootPath),
"multi(0)disk(0)cdrom(%u)", FrldrBootDrive - 0x80); "multi(0)disk(0)cdrom(%u)", FrldrBootDrive - 0x80);
} }
else else
@ -420,7 +420,7 @@ DiskGetBootPath(BOOLEAN IsPxe)
FrldrBootPartition = BootPartition; FrldrBootPartition = BootPartition;
RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath), RtlStringCbPrintfA(FrLdrBootPath, sizeof(FrLdrBootPath),
"multi(0)disk(0)rdisk(%u)partition(%lu)", "multi(0)disk(0)rdisk(%u)partition(%lu)",
FrldrBootDrive - 0x80, FrldrBootPartition); FrldrBootDrive - 0x80, FrldrBootPartition);
} }
@ -437,7 +437,7 @@ PcInitializeBootDevices(VOID)
DiskCount = EnumerateHarddisks(&BootDriveReported); DiskCount = EnumerateHarddisks(&BootDriveReported);
/* Initialize FrldrBootPath, the boot path we're booting from (the "SystemPartition") */ /* Initialize FrLdrBootPath, the boot path we're booting from (the "SystemPartition") */
DiskGetBootPath(PxeInit()); DiskGetBootPath(PxeInit());
/* Add it, if it's a floppy or cdrom */ /* Add it, if it's a floppy or cdrom */
@ -473,9 +473,9 @@ PcInitializeBootDevices(VOID)
TRACE("Checksum: %x\n", Checksum); TRACE("Checksum: %x\n", Checksum);
/* Fill out the ARC disk block */ /* Fill out the ARC disk block */
AddReactOSArcDiskInfo(FrldrBootPath, Signature, Checksum, TRUE); AddReactOSArcDiskInfo(FrLdrBootPath, Signature, Checksum, TRUE);
FsRegisterDevice(FrldrBootPath, &DiskVtbl); FsRegisterDevice(FrLdrBootPath, &DiskVtbl);
DiskCount++; // This is not accounted for in the number of pre-enumerated BIOS drives! DiskCount++; // This is not accounted for in the number of pre-enumerated BIOS drives!
TRACE("Additional boot drive detected: 0x%02X\n", (int)FrldrBootDrive); TRACE("Additional boot drive detected: 0x%02X\n", (int)FrldrBootDrive);
} }

View file

@ -24,7 +24,6 @@
#include "compat.h" #include "compat.h"
extern void BootMain( PSTR CmdLine ); extern void BootMain( PSTR CmdLine );
extern const PCSTR GetFreeLoaderVersionString(VOID);
extern ULONG CacheSizeLimit; extern ULONG CacheSizeLimit;
of_proxy ofproxy; of_proxy ofproxy;
void *PageDirectoryStart, *PageDirectoryEnd; void *PageDirectoryStart, *PageDirectoryEnd;
@ -32,7 +31,7 @@ static int chosen_package, stdin_handle, stdout_handle, part_handle = -1;
int mmu_handle = 0; int mmu_handle = 0;
int claimed[4]; int claimed[4];
BOOLEAN AcpiPresent = FALSE; BOOLEAN AcpiPresent = FALSE;
CHAR FrldrBootPath[MAX_PATH] = "", BootPart[MAX_PATH] = "", CmdLine[MAX_PATH] = "bootprep"; CHAR FrLdrBootPath[MAX_PATH] = "", BootPart[MAX_PATH] = "", CmdLine[MAX_PATH] = "bootprep";
jmp_buf jmp; jmp_buf jmp;
volatile char *video_mem = 0; volatile char *video_mem = 0;
@ -468,7 +467,7 @@ void PpcOfwInit()
return; return;
} }
printf( "FreeLDR version [%s]\n", GetFreeLoaderVersionString() ); printf( "FreeLDR version [%s]\n", FrLdrVersionString );
BootMain( CmdLine ); BootMain( CmdLine );
} }
@ -487,7 +486,7 @@ void MachInit(const char *CmdLine) {
char *sep; char *sep;
BootPart[0] = 0; BootPart[0] = 0;
FrldrBootPath[0] = 0; FrLdrBootPath[0] = 0;
printf( "Determining boot device: [%s]\n", CmdLine ); printf( "Determining boot device: [%s]\n", CmdLine );
@ -505,18 +504,18 @@ void MachInit(const char *CmdLine) {
if( strlen(BootPart) == 0 ) { if( strlen(BootPart) == 0 ) {
if (ofproxy) if (ofproxy)
len = ofw_getprop(chosen_package, "bootpath", len = ofw_getprop(chosen_package, "bootpath",
FrldrBootPath, sizeof(FrldrBootPath)); FrLdrBootPath, sizeof(FrLdrBootPath));
else else
len = 0; len = 0;
if( len < 0 ) len = 0; if( len < 0 ) len = 0;
FrldrBootPath[len] = 0; FrLdrBootPath[len] = 0;
printf( "Boot Path: %s\n", FrldrBootPath ); printf( "Boot Path: %s\n", FrLdrBootPath );
sep = strrchr(FrldrBootPath, ','); sep = strrchr(FrLdrBootPath, ',');
strcpy(BootPart, FrldrBootPath); strcpy(BootPart, FrLdrBootPath);
if( sep ) { if( sep ) {
BootPart[sep - FrldrBootPath] = 0; BootPart[sep - FrLdrBootPath] = 0;
} }
} }

View file

@ -141,7 +141,7 @@ void PpcPrepInit()
MachVtbl.HwDetect = PpcPrepHwDetect; MachVtbl.HwDetect = PpcPrepHwDetect;
MachVtbl.HwIdle = PcPrepHwIdle; MachVtbl.HwIdle = PcPrepHwIdle;
printf( "FreeLDR version [%s]\n", GetFreeLoaderVersionString() ); printf( "FreeLDR version [%s]\n", FrLdrVersionString );
BootMain( "" ); BootMain( "" );
} }

View file

@ -39,10 +39,8 @@ DissectArcPath(
/* Get the path (optional) */ /* Get the path (optional) */
if (Path) if (Path)
{ *Path = ArcPath + 10;
p = ArcPath + 11;
*Path = p;
}
return TRUE; return TRUE;
} }

View file

@ -109,7 +109,7 @@ BuildArgvForOsLoader(
Size = 0; Size = 0;
/* i == 0: Program name */ /* i == 0: Program name */
/* i == 1: SystemPartition : from where FreeLdr has been started */ /* i == 1: SystemPartition : from where FreeLdr has been started */
Size += (strlen("SystemPartition=") + strlen(FrldrBootPath) + 1) * sizeof(CHAR); Size += (strlen("SystemPartition=") + strlen(FrLdrBootPath) + 1) * sizeof(CHAR);
/* i == 2: LoadIdentifier : ASCII string that may be used to associate an identifier with a set of load parameters */ /* i == 2: LoadIdentifier : ASCII string that may be used to associate an identifier with a set of load parameters */
if (LoadIdentifier) if (LoadIdentifier)
{ {
@ -135,7 +135,7 @@ BuildArgvForOsLoader(
/* i == 1: SystemPartition */ /* i == 1: SystemPartition */
{ {
strcpy(SettingName, "SystemPartition="); strcpy(SettingName, "SystemPartition=");
strcat(SettingName, FrldrBootPath); strcat(SettingName, FrLdrBootPath);
*Args++ = SettingName; *Args++ = SettingName;
SettingName += (strlen(SettingName) + 1); SettingName += (strlen(SettingName) + 1);
@ -197,21 +197,24 @@ VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
DriveMapMapDrivesInSection(SectionId); DriveMapMapDrivesInSection(SectionId);
#endif #endif
/* Loop through the OS loading method table and find a suitable OS to boot */ /* Find the suitable OS loader to start */
for (i = 0; i < sizeof(OSLoadingMethods) / sizeof(OSLoadingMethods[0]); ++i) for (i = 0; ; ++i)
{ {
if (i >= RTL_NUMBER_OF(OSLoadingMethods))
return;
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0) if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
{ break;
}
/* Build the ARC-compatible argument vector */
Argv = BuildArgvForOsLoader(OperatingSystem->LoadIdentifier, SectionId, &Argc); Argv = BuildArgvForOsLoader(OperatingSystem->LoadIdentifier, SectionId, &Argc);
if (Argv) if (!Argv)
{ return; // Unexpected failure.
/* Start the OS loader */
OSLoadingMethods[i].OsLoader(Argc, Argv, NULL); OSLoadingMethods[i].OsLoader(Argc, Argv, NULL);
FrLdrHeapFree(Argv, TAG_STRING); FrLdrHeapFree(Argv, TAG_STRING);
} }
return;
}
}
}
#ifdef HAS_OPTION_MENU_EDIT_CMDLINE #ifdef HAS_OPTION_MENU_EDIT_CMDLINE
@ -231,15 +234,17 @@ VOID EditOperatingSystemEntry(IN OperatingSystemItem* OperatingSystem)
/* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */ /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
ASSERT(*BootType); ASSERT(*BootType);
/* Loop through the OS loading method table and find a suitable OS entry editor */ /* Find the suitable OS entry editor */
for (i = 0; i < sizeof(OSLoadingMethods) / sizeof(OSLoadingMethods[0]); ++i) for (i = 0; ; ++i)
{ {
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0) if (i >= RTL_NUMBER_OF(OSLoadingMethods))
{
OSLoadingMethods[i].EditOsEntry(OperatingSystem);
return; return;
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
break;
} }
}
/* Run it */
OSLoadingMethods[i].EditOsEntry(OperatingSystem);
} }
#endif // HAS_OPTION_MENU_EDIT_CMDLINE #endif // HAS_OPTION_MENU_EDIT_CMDLINE

View file

@ -61,7 +61,7 @@ VOID OptionMenuCustomBoot(VOID)
if (!UiDisplayMenu("Please choose a boot method:", NULL, if (!UiDisplayMenu("Please choose a boot method:", NULL,
FALSE, FALSE,
CustomBootMenuList, CustomBootMenuList,
sizeof(CustomBootMenuList) / sizeof(CustomBootMenuList[0]), RTL_NUMBER_OF(CustomBootMenuList),
0, -1, 0, -1,
&SelectedMenuItem, &SelectedMenuItem,
TRUE, TRUE,
@ -123,7 +123,7 @@ EditCustomBootDisk(
TIMEINFO* TimeInfo; TIMEINFO* TimeInfo;
ULONG_PTR SectionId = OperatingSystem->SectionId; ULONG_PTR SectionId = OperatingSystem->SectionId;
CHAR SectionName[100]; CHAR SectionName[100];
/* The following is a trick for saving some stack space */ /* This construct is a trick for saving some stack space */
union union
{ {
struct struct
@ -218,7 +218,7 @@ EditCustomBootPartition(
TIMEINFO* TimeInfo; TIMEINFO* TimeInfo;
ULONG_PTR SectionId = OperatingSystem->SectionId; ULONG_PTR SectionId = OperatingSystem->SectionId;
CHAR SectionName[100]; CHAR SectionName[100];
/* The following is a trick for saving some stack space */ /* This construct is a trick for saving some stack space */
union union
{ {
struct struct
@ -328,7 +328,7 @@ EditCustomBootSectorFile(
TIMEINFO* TimeInfo; TIMEINFO* TimeInfo;
ULONG_PTR SectionId = OperatingSystem->SectionId; ULONG_PTR SectionId = OperatingSystem->SectionId;
CHAR SectionName[100]; CHAR SectionName[100];
/* The following is a trick for saving some stack space */ /* This construct is a trick for saving some stack space */
union union
{ {
struct struct
@ -461,7 +461,7 @@ EditCustomBootLinux(
TIMEINFO* TimeInfo; TIMEINFO* TimeInfo;
ULONG_PTR SectionId = OperatingSystem->SectionId; ULONG_PTR SectionId = OperatingSystem->SectionId;
CHAR SectionName[100]; CHAR SectionName[100];
/* The following is a trick for saving some stack space */ /* This construct is a trick for saving some stack space */
union union
{ {
struct struct

View file

@ -1611,7 +1611,7 @@ LoadBootDeviceDriver(VOID)
InitializeListHead(&ModuleListHead); InitializeListHead(&ModuleListHead);
/* Create full ntbootdd.sys path */ /* Create full ntbootdd.sys path */
strcpy(NtBootDdPath, FrldrBootPath); strcpy(NtBootDdPath, FrLdrBootPath);
strcat(NtBootDdPath, "\\NTBOOTDD.SYS"); strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
/* Load file */ /* Load file */

View file

@ -26,7 +26,17 @@ DBG_DEFAULT_CHANNEL(WARNING);
/* GLOBALS ********************************************************************/ /* GLOBALS ********************************************************************/
CCHAR FrldrBootPath[MAX_PATH] = ""; #define TOSTRING_(X) #X
#define TOSTRING(X) TOSTRING_(X)
const PCSTR FrLdrVersionString =
#if (FREELOADER_PATCH_VERSION == 0)
"FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION);
#else
"FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION) "." TOSTRING(FREELOADER_PATCH_VERSION);
#endif
CCHAR FrLdrBootPath[MAX_PATH] = "";
/* FUNCTIONS ******************************************************************/ /* FUNCTIONS ******************************************************************/

View file

@ -123,7 +123,7 @@ extern SIZE_T DiskReadBufferSize;
/* ARC path of the boot drive and partition */ /* ARC path of the boot drive and partition */
extern CCHAR FrldrBootPath[MAX_PATH]; extern CCHAR FrLdrBootPath[MAX_PATH];
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////

View file

@ -36,4 +36,4 @@
#define FREELOADER_MINOR_VERSION 0 #define FREELOADER_MINOR_VERSION 0
#define FREELOADER_PATCH_VERSION 0 #define FREELOADER_PATCH_VERSION 0
const PCSTR GetFreeLoaderVersionString(VOID); extern const PCSTR FrLdrVersionString;

View file

@ -34,7 +34,7 @@ BOOLEAN IniFileInitialize(VOID)
TRACE("IniFileInitialize()\n"); TRACE("IniFileInitialize()\n");
/* Try to open freeldr.ini */ /* Try to open freeldr.ini */
Status = FsOpenFile("freeldr.ini", FrldrBootPath, OpenReadOnly, &FileId); Status = FsOpenFile("freeldr.ini", FrLdrBootPath, OpenReadOnly, &FileId);
if (Status != ESUCCESS) if (Status != ESUCCESS)
{ {
ERR("Error while opening freeldr.ini, Status: %d\n", Status); ERR("Error while opening freeldr.ini, Status: %d\n", Status);

View file

@ -110,7 +110,7 @@ VOID TuiDrawBackdrop(VOID)
// //
TuiDrawText(2, TuiDrawText(2,
1, 1,
GetFreeLoaderVersionString(), FrLdrVersionString,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
// //

View file

@ -1,35 +0,0 @@
/*
* 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.
*/
#include <freeldr.h>
#define TOSTRING_(X) #X
#define TOSTRING(X) TOSTRING_(X)
static const PCSTR FreeLoaderVersionString =
#if (FREELOADER_PATCH_VERSION == 0)
"FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION);
#else
"FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION) "." TOSTRING(FREELOADER_PATCH_VERSION);
#endif
const PCSTR GetFreeLoaderVersionString(VOID)
{
return FreeLoaderVersionString;
}