ReactOS 0.4.16-dev-2104-gb84fa49
settings.c
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * or MIT (https://spdx.org/licenses/MIT)
5 * PURPOSE: Command-line parsing and global settings management
6 * COPYRIGHT: Copyright 2008-2010 ReactOS Portable Systems Group <ros.arm@reactos.org>
7 * Copyright 2015-2024 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
8 */
9
10/* INCLUDES *******************************************************************/
11
12#include <freeldr.h>
13
14/* GLOBALS ********************************************************************/
15
16static CCHAR DebugString[256];
17static CCHAR VideoOptions[128];
18static CCHAR DefaultOs[256];
20
21/* FUNCTIONS ******************************************************************/
22
23static VOID
26{
27 PCHAR Setting;
28 size_t Length;
29 ULONG_PTR Offset = 0;
30
31 /*
32 * Get the debug string, in the following format:
33 * "debug=option1=XXX;option2=YYY;..."
34 * and translate it into the format:
35 * "OPTION1=XXX OPTION2=YYY ..."
36 */
37 Setting = strstr(CmdLine, "debug=");
38 if (Setting)
39 {
40 /* Check if there are more command-line parameters following */
41 Setting += sizeof("debug=") - sizeof(ANSI_NULL);
42 Length = strcspn(Setting, " \t");
43
44 /* Copy the debug string and upcase it */
47
48 /* Replace all separators ';' by spaces */
49 Setting = DebugString;
50 while (*Setting)
51 {
52 if (*Setting == ';') *Setting = ' ';
53 Setting++;
54 }
55
57 }
58
59 /* Get the video options */
60 Setting = strstr(CmdLine, "video=");
61 if (Setting)
62 {
63 Setting += sizeof("video=") - sizeof(ANSI_NULL);
64 }
65#if (defined(_M_IX86) || defined(_M_AMD64)) && !defined(SARCH_XBOX) && !defined(SARCH_PC98)
66 else
67 {
68 Setting = strstr(CmdLine, "vga=");
69 if (Setting)
70 Setting += sizeof("vga=") - sizeof(ANSI_NULL);
71 }
72#endif
73 if (Setting)
74 {
75 /* Check if there are more command-line parameters following */
76 Length = strcspn(Setting, " \t");
77
78 /* Copy the string */
81 }
82
83 /* Get the timeout */
84 Setting = strstr(CmdLine, "timeout=");
85 if (Setting)
86 {
87 BootMgrInfo.TimeOut = atoi(Setting +
88 sizeof("timeout=") - sizeof(ANSI_NULL));
89 }
90
91 /* Get the default OS */
92 Setting = strstr(CmdLine, "defaultos=");
93 if (Setting)
94 {
95 /* Check if there are more command-line parameters following */
96 Setting += sizeof("defaultos=") - sizeof(ANSI_NULL);
97 Length = strcspn(Setting, " \t");
98
99 /* Copy the default OS */
100 RtlStringCbCopyNA(DefaultOs, sizeof(DefaultOs), Setting, Length);
102 }
103
104 /* Get the ramdisk base address */
105 Setting = strstr(CmdLine, "rdbase=");
106 if (Setting)
107 {
109 (PVOID)(ULONG_PTR)strtoull(Setting +
110 sizeof("rdbase=") - sizeof(ANSI_NULL),
111 NULL, 0);
112 }
113
114 /* Get the ramdisk size */
115 Setting = strstr(CmdLine, "rdsize=");
116 if (Setting)
117 {
118 gInitRamDiskSize = strtoul(Setting +
119 sizeof("rdsize=") - sizeof(ANSI_NULL),
120 NULL, 0);
121 }
122
123 /* Get the ramdisk offset */
124 Setting = strstr(CmdLine, "rdoffset=");
125 if (Setting)
126 {
127 Offset = strtoul(Setting +
128 sizeof("rdoffset=") - sizeof(ANSI_NULL),
129 NULL, 0);
130 }
131
132 /* Fix it up */
134}
135
136VOID
139{
140 /* Pre-initialization: The settings originate from the command-line.
141 * Main initialization: Overwrite them if needed with those from freeldr.ini */
142 if (CmdLine)
143 {
145 return;
146 }
148 {
149 // ERR("LoadSettings() called but no freeldr.ini\n");
150 return;
151 }
152
153 BOOLEAN FoundLoaderSection = FALSE;
154 PCSTR LoaderSections[] = {
155 "FreeLoader",
156 "Boot Loader",
157 "FlexBoot",
158 "MultiBoot",
159 };
160
161 /* Search for the first section in LoaderSections and load the settings,
162 * prioritizing the order in the file.
163 * If a section is already loaded, skip further checks. */
165 {
166 for (ULONG i = 0; i < sizeof(LoaderSections) / sizeof(LoaderSections[0]); i++)
167 {
168 PCSTR Section = LoaderSections[i];
169
171 {
172 FoundLoaderSection = TRUE;
173 break;
174 }
175 }
176
177 if (!FoundLoaderSection)
178 {
179 UiMessageBoxCritical("Bootloader Section not found in freeldr.ini");
180 return;
181 }
182 }
183
184 /* Get the debug string. Always override it with the one from freeldr.ini */
186 DebugString, sizeof(DebugString)))
187 {
189 }
190
191 /* Get the timeout. Keep the existing one if it is valid,
192 * otherwise retrieve it from freeldr.ini */
193 if (BootMgrInfo.TimeOut < 0)
194 {
195 CHAR TimeOutText[20];
196 BootMgrInfo.TimeOut = -1;
198 TimeOutText, sizeof(TimeOutText)))
199 {
200 BootMgrInfo.TimeOut = atoi(TimeOutText);
201 }
202 }
203
204 /* Get the default OS */
206 {
208 DefaultOs, sizeof(DefaultOs)))
209 {
211 }
212 }
213}
214
216{
217 return &BootMgrInfo;
218}
219
220/* EOF */
unsigned char BOOLEAN
void LoadSettings(void)
Definition: settings.c:53
PVOID gInitRamDiskBase
Definition: ramdisk.c:20
ULONG gInitRamDiskSize
Definition: ramdisk.c:21
VOID UiMessageBoxCritical(_In_ PCSTR MessageText)
Definition: ui.c:372
static CCHAR VideoOptions[128]
Definition: settings.c:17
static CCHAR DebugString[256]
Definition: settings.c:16
BOOTMGRINFO BootMgrInfo
Definition: settings.c:19
static VOID CmdLineParse(_In_ PCSTR CmdLine)
Definition: settings.c:24
PBOOTMGRINFO GetBootMgrInfo(VOID)
Definition: settings.c:215
static CCHAR DefaultOs[256]
Definition: settings.c:18
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_ACRTIMP int __cdecl atoi(const char *)
Definition: string.c:1715
_ACRTIMP __msvcrt_ulong __cdecl strtoul(const char *, char **, int)
Definition: string.c:1859
_ACRTIMP size_t __cdecl strcspn(const char *, const char *)
Definition: string.c:3493
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3415
static const WCHAR CmdLine[]
Definition: install.c:48
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:154
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:30
PLIST_ENTRY IniGetFileSectionListHead(VOID)
Definition: inifile.c:25
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
#define ANSI_NULL
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTRSAFEAPI RtlStringCbCopyNA(_Out_writes_bytes_(cbDest) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCSTR pszSrc, _In_ size_t cbToCopy)
Definition: ntstrsafe.h:395
_strupr
Definition: string.h:453
#define strtoull
Definition: stabs.c:58
PCSTR VideoOptions
Definition: settings.h:13
PCSTR DefaultOs
Definition: settings.h:14
LONG TimeOut
Definition: settings.h:15
PCSTR DebugString
Definition: settings.h:12
ULONG_PTR FrLdrSection
Definition: settings.h:16
void * PVOID
Definition: typedefs.h:50
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
char CCHAR
Definition: typedefs.h:51
char * PCHAR
Definition: typedefs.h:51
char CHAR
Definition: xmlstorage.h:175