ReactOS 0.4.16-dev-117-g38f21f9
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 /* Open the [FreeLoader] section and load the settings */
130 if ((BootMgrInfo.FrLdrSection == 0) &&
131 !IniOpenSection("FreeLoader", &BootMgrInfo.FrLdrSection))
132 {
133 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini");
134 return;
135 }
136
137 /* Get the debug string. Always override it with the one from freeldr.ini */
139 DebugString, sizeof(DebugString)))
140 {
142 }
143
144 /* Get the timeout. Keep the existing one if it is valid,
145 * otherwise retrieve it from freeldr.ini */
146 if (BootMgrInfo.TimeOut < 0)
147 {
148 CHAR TimeOutText[20];
149 BootMgrInfo.TimeOut = -1;
151 TimeOutText, sizeof(TimeOutText)))
152 {
153 BootMgrInfo.TimeOut = atoi(TimeOutText);
154 }
155 }
156
157 /* Get the default OS */
159 {
161 DefaultOs, sizeof(DefaultOs)))
162 {
164 }
165 }
166}
167
168/* EOF */
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
static const WCHAR CmdLine[]
Definition: install.c:48
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
_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: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
#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
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
char CCHAR
Definition: typedefs.h:51
char * PCHAR
Definition: typedefs.h:51
char CHAR
Definition: xmlstorage.h:175