ReactOS 0.4.16-dev-527-gdad3a09
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 DefaultOs[256];
19
20/* FUNCTIONS ******************************************************************/
21
22static VOID
25{
26 PCHAR End, Setting;
28
29 /*
30 * Get the debug string, in the following format:
31 * "debug=option1=XXX;option2=YYY;..."
32 * and translate it into the format:
33 * "OPTION1=XXX OPTION2=YYY ..."
34 */
35 Setting = strstr(CmdLine, "debug=");
36 if (Setting)
37 {
38 /* Check if there are more command-line parameters following */
39 Setting += sizeof("debug=") - sizeof(ANSI_NULL);
40 End = strstr(Setting, " ");
41 Length = (End ? (End - Setting) : strlen(Setting));
42
43 /* Copy the debug string and upcase it */
46
47 /* Replace all separators ';' by spaces */
48 Setting = DebugString;
49 while (*Setting)
50 {
51 if (*Setting == ';') *Setting = ' ';
52 Setting++;
53 }
54
56 }
57
58 /* Get the timeout */
59 Setting = strstr(CmdLine, "timeout=");
60 if (Setting)
61 {
62 BootMgrInfo.TimeOut = atoi(Setting +
63 sizeof("timeout=") - sizeof(ANSI_NULL));
64 }
65
66 /* Get the default OS */
67 Setting = strstr(CmdLine, "defaultos=");
68 if (Setting)
69 {
70 /* Check if there are more command-line parameters following */
71 Setting += sizeof("defaultos=") - sizeof(ANSI_NULL);
72 End = strstr(Setting, " ");
73 Length = (End ? (End - Setting) : strlen(Setting));
74
75 /* Copy the default OS */
76 RtlStringCbCopyNA(DefaultOs, sizeof(DefaultOs), Setting, Length);
78 }
79
80 /* Get the ramdisk base address */
81 Setting = strstr(CmdLine, "rdbase=");
82 if (Setting)
83 {
85 (PVOID)(ULONG_PTR)strtoull(Setting +
86 sizeof("rdbase=") - sizeof(ANSI_NULL),
87 NULL, 0);
88 }
89
90 /* Get the ramdisk size */
91 Setting = strstr(CmdLine, "rdsize=");
92 if (Setting)
93 {
94 gInitRamDiskSize = strtoul(Setting +
95 sizeof("rdsize=") - sizeof(ANSI_NULL),
96 NULL, 0);
97 }
98
99 /* Get the ramdisk offset */
100 Setting = strstr(CmdLine, "rdoffset=");
101 if (Setting)
102 {
103 Offset = strtoul(Setting +
104 sizeof("rdoffset=") - sizeof(ANSI_NULL),
105 NULL, 0);
106 }
107
108 /* Fix it up */
110}
111
112VOID
115{
116 /* Pre-initialization: The settings originate from the command-line.
117 * Main initialization: Overwrite them if needed with those from freeldr.ini */
118 if (CmdLine)
119 {
121 return;
122 }
124 {
125 // ERR("LoadSettings() called but no freeldr.ini\n");
126 return;
127 }
128
129 BOOLEAN FoundLoaderSection = FALSE;
130 PCSTR LoaderSections[] = {
131 "FreeLoader",
132 "Boot Loader",
133 "FlexBoot",
134 "MultiBoot",
135 };
136
137 /* Search for the first section in LoaderSections and load the settings,
138 * prioritizing the order in the file.
139 * If a section is already loaded, skip further checks. */
141 {
142 for (ULONG i = 0; i < sizeof(LoaderSections) / sizeof(LoaderSections[0]); i++)
143 {
144 PCSTR Section = LoaderSections[i];
145
147 {
148 FoundLoaderSection = TRUE;
149 break;
150 }
151 }
152
153 if (!FoundLoaderSection)
154 {
155 UiMessageBoxCritical("Bootloader Section not found in freeldr.ini");
156 return;
157 }
158 }
159
160 /* Get the debug string. Always override it with the one from freeldr.ini */
162 DebugString, sizeof(DebugString)))
163 {
165 }
166
167 /* Get the timeout. Keep the existing one if it is valid,
168 * otherwise retrieve it from freeldr.ini */
169 if (BootMgrInfo.TimeOut < 0)
170 {
171 CHAR TimeOutText[20];
172 BootMgrInfo.TimeOut = -1;
174 TimeOutText, sizeof(TimeOutText)))
175 {
176 BootMgrInfo.TimeOut = atoi(TimeOutText);
177 }
178 }
179
180 /* Get the default OS */
182 {
184 DefaultOs, sizeof(DefaultOs)))
185 {
187 }
188 }
189}
190
191/* EOF */
unsigned char BOOLEAN
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void LoadSettings(void)
Definition: settings.c:53
PVOID gInitRamDiskBase
Definition: ramdisk.c:17
ULONG gInitRamDiskSize
Definition: ramdisk.c:18
VOID UiMessageBoxCritical(_In_ PCSTR MessageText)
Definition: ui.c:372
static CCHAR DebugString[256]
Definition: settings.c:16
BOOTMGRINFO BootMgrInfo
Definition: settings.c:18
static VOID CmdLineParse(_In_ PCSTR CmdLine)
Definition: settings.c:23
static CCHAR DefaultOs[256]
Definition: settings.c:17
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
LIST_ENTRY IniFileSectionListHead
Definition: parse.c:25
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:149
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
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 DefaultOs
Definition: settings.h:13
LONG TimeOut
Definition: settings.h:14
PCSTR DebugString
Definition: settings.h:12
ULONG_PTR FrLdrSection
Definition: settings.h:15
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