ReactOS 0.4.16-dev-456-ga97fcf1
settings.c File Reference
#include <freeldr.h>
Include dependency graph for settings.c:

Go to the source code of this file.

Functions

static VOID CmdLineParse (_In_ PCSTR CmdLine)
 
VOID LoadSettings (_In_opt_ PCSTR CmdLine)
 

Variables

static CCHAR DebugString [256]
 
static CCHAR DefaultOs [256]
 
BOOTMGRINFO BootMgrInfo = {NULL, NULL, -1, 0}
 

Function Documentation

◆ CmdLineParse()

static VOID CmdLineParse ( _In_ PCSTR  CmdLine)
static

Definition at line 23 of file settings.c.

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}
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
PVOID gInitRamDiskBase
Definition: ramdisk.c:17
ULONG gInitRamDiskSize
Definition: ramdisk.c:18
static CCHAR DebugString[256]
Definition: settings.c:16
BOOTMGRINFO BootMgrInfo
Definition: settings.c:18
static CCHAR DefaultOs[256]
Definition: settings.c:17
#define NULL
Definition: types.h:112
static const WCHAR CmdLine[]
Definition: install.c:48
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#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
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
#define strtoull
Definition: stabs.c:58
PCSTR DefaultOs
Definition: settings.h:13
LONG TimeOut
Definition: settings.h:14
PCSTR DebugString
Definition: settings.h:12
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
char * PCHAR
Definition: typedefs.h:51

Referenced by LoadSettings().

◆ LoadSettings()

VOID LoadSettings ( _In_opt_ PCSTR  CmdLine)

Definition at line 113 of file settings.c.

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}
unsigned char BOOLEAN
VOID UiMessageBoxCritical(_In_ PCSTR MessageText)
Definition: ui.c:372
static VOID CmdLineParse(_In_ PCSTR CmdLine)
Definition: settings.c:23
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#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
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
ULONG_PTR FrLdrSection
Definition: settings.h:15
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG
Definition: typedefs.h:59
char CHAR
Definition: xmlstorage.h:175

Variable Documentation

◆ BootMgrInfo

◆ DebugString

◆ DefaultOs

CCHAR DefaultOs[256]
static

Definition at line 17 of file settings.c.

Referenced by CmdLineParse(), and LoadSettings().