ReactOS 0.4.17-dev-116-ga4b6fe9
ntldropts.c File Reference
#include <freeldr.h>
#include "ntldropts.h"
Include dependency graph for ntldropts.c:

Go to the source code of this file.

Functions

PCSTR NtLdrGetNextOption (_Inout_ PCSTR *Options, _Out_opt_ PULONG OptionLength)
 
PCSTR NtLdrGetOptionExN (_In_ PCSTR Options, _In_reads_(OptNameLength) PCCH OptionName, _In_ ULONG OptNameLength, _Out_opt_ PULONG OptionLength)
 
PCSTR NtLdrGetOptionEx (_In_ PCSTR Options, _In_ PCSTR OptionName, _Out_opt_ PULONG OptionLength)
 
PCSTR NtLdrGetOption (_In_ PCSTR Options, _In_ PCSTR OptionName)
 
VOID NtLdrAddOptions (_Inout_updates_z_(BufferSize) PSTR Options, _In_ ULONG BufferSize, _In_ BOOLEAN Append, _In_opt_ PCSTR NewOptions)
 Appends or prepends new options to the ones originally contained in the buffer pointed by Options, of maximum size BufferSize.
 
VOID NtLdrUpdateOptions (_Inout_updates_z_(BufferSize) PSTR LoadOptions, _In_ ULONG BufferSize, _In_ BOOLEAN Append, _In_opt_ PCSTR OptionsToAdd[], _In_opt_ PCSTR OptionsToRemove[])
 Updates the options in the buffer pointed by LoadOptions, of maximum size BufferSize, by first removing any specified options, and then adding any other ones.
 

Function Documentation

◆ NtLdrAddOptions()

VOID NtLdrAddOptions ( _Inout_updates_z_(BufferSize) PSTR  Options,
_In_ ULONG  BufferSize,
_In_ BOOLEAN  Append,
_In_opt_ PCSTR  NewOptions 
)

Appends or prepends new options to the ones originally contained in the buffer pointed by Options, of maximum size BufferSize.

Definition at line 141 of file ntldropts.c.

146{
147 ULONG OptionsLength;
148 ULONG NewOptsLength;
150
151 if (!Options || (BufferSize == 0))
152 return;
153 // ASSERT(strlen(Options) + 1 <= BufferSize);
154
155 if (!NewOptions || !*NewOptions)
156 return;
157
158 if (Append)
159 {
160 OptionsLength = (ULONG)strlen(Options);
161 OptionsLength = min(OptionsLength, BufferSize-1);
162
163 /* Add a whitespace separator if needed */
164 if (OptionsLength != 0 &&
165 (Options[OptionsLength-1] != ' ') &&
166 (Options[OptionsLength-1] != '\t') &&
167 (*NewOptions != '\0') &&
168 (*NewOptions != ' ') &&
169 (*NewOptions != '\t'))
170 {
171 RtlStringCbCatA(Options, BufferSize * sizeof(CHAR), " ");
172 }
173
174 /* Append the options */
175 RtlStringCbCatA(Options, BufferSize * sizeof(CHAR), NewOptions);
176 }
177 else
178 {
179 NewOptsLength = (ULONG)strlen(NewOptions);
180 NewOptsLength = min(NewOptsLength, BufferSize-1);
181
182 /* Add a whitespace separator if needed */
184 if (NewOptsLength != 0 &&
185 (NewOptions[NewOptsLength-1] != ' ') &&
186 (NewOptions[NewOptsLength-1] != '\t') &&
187 (*Options != '\0') &&
188 (*Options != ' ') &&
189 (*Options != '\t'))
190 {
192 ++NewOptsLength;
193 }
194
195 /*
196 * Move the original load options forward (possibly truncating them
197 * at the end if the buffer is not large enough) to make place for
198 * the options to prepend.
199 */
200 OptionsLength = (ULONG)strlen(Options) + 1;
201 OptionsLength = min(OptionsLength, BufferSize - NewOptsLength);
202 RtlMoveMemory(Options + NewOptsLength,
203 Options,
204 OptionsLength * sizeof(CHAR));
205 /* NULL-terminate */
206 (Options + NewOptsLength)[OptionsLength-1] = '\0';
207
208 /* Restore the new options length back to its original value */
209 if (AddSeparator)
210 --NewOptsLength;
211 /* Prepend the options and add the whitespace separator if needed */
212 strncpy(Options, NewOptions, NewOptsLength);
213 if (AddSeparator)
214 Options[NewOptsLength] = ' ';
215 }
216}
unsigned char BOOLEAN
Definition: actypes.h:127
static void AddSeparator(HWND hwndToolBar)
Definition: wordpad.c:169
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
#define min(a, b)
Definition: monoChain.cc:55
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625
char CHAR
Definition: pedump.c:57
strncpy
Definition: string.h:335
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint32_t ULONG
Definition: typedefs.h:59
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by AppendBootTimeOptions(), and NtLdrUpdateOptions().

◆ NtLdrGetNextOption()

PCSTR NtLdrGetNextOption ( _Inout_ PCSTR Options,
_Out_opt_ PULONG  OptionLength 
)

Definition at line 18 of file ntldropts.c.

21{
23 PCSTR Option = NULL;
24 ULONG Length = 0;
25
26 if (OptionLength)
27 *OptionLength = 0;
28
29 if (!Options || !*Options)
30 return NULL;
31
32 /* Loop over each option */
34 while (*NextOption)
35 {
36 /* Skip possible initial whitespace */
37 NextOption += strspn(NextOption, " \t");
38
39 /* Stop now if we have already found an option.
40 * NextOption points to the next following option. */
41 if (Option)
42 break;
43
44 /* Check whether a new option starts. Options are delimited
45 * with an option separator '/' or with whitespace. */
46 if (*NextOption == '/')
47 ++NextOption;
48
49 /* Get the actual length of the option until
50 * the next whitespace or option separator. */
51 Length = (ULONG)strcspn(NextOption, " \t/");
52
53 /* Retrieve the option if present and go to the beginning of the next one */
54 if (Length != 0)
55 Option = NextOption;
56
57 /* Restart after the end of the option */
59 }
60
62 if (Option && OptionLength)
63 *OptionLength = Length;
64 return Option;
65}
#define NULL
Definition: types.h:112
_ACRTIMP size_t __cdecl strcspn(const char *, const char *)
Definition: string.c:3493
_ACRTIMP size_t __cdecl strspn(const char *, const char *)
Definition: string.c:3515
static char * NextOption(const char *const ostr)
Definition: getopt.c:31
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
const char * PCSTR
Definition: typedefs.h:52

Referenced by NtLdrGetHigherPriorityOptions(), NtLdrGetOptionExN(), NtLdrNormalizeOptions(), and NtLdrUpdateOptions().

◆ NtLdrGetOption()

PCSTR NtLdrGetOption ( _In_ PCSTR  Options,
_In_ PCSTR  OptionName 
)

Definition at line 128 of file ntldropts.c.

131{
132 return NtLdrGetOptionEx(Options, OptionName, NULL);
133}
PCSTR NtLdrGetOptionEx(_In_ PCSTR Options, _In_ PCSTR OptionName, _Out_opt_ PULONG OptionLength)
Definition: ntldropts.c:117

Referenced by GetSerialMouseDetectionBitmap(), LoadAndBootWindows(), LoadAndBootWindowsCommon(), LoadReactOSSetup(), LoadWindowsCore(), RamDiskInitialize(), and WinLdrSetupEms().

◆ NtLdrGetOptionEx()

PCSTR NtLdrGetOptionEx ( _In_ PCSTR  Options,
_In_ PCSTR  OptionName,
_Out_opt_ PULONG  OptionLength 
)

Definition at line 117 of file ntldropts.c.

121{
122 return NtLdrGetOptionExN(Options, OptionName,
123 (ULONG)strlen(OptionName),
124 OptionLength);
125}
PCSTR NtLdrGetOptionExN(_In_ PCSTR Options, _In_reads_(OptNameLength) PCCH OptionName, _In_ ULONG OptNameLength, _Out_opt_ PULONG OptionLength)
Definition: ntldropts.c:73

Referenced by GetSerialMouseDetectionBitmap(), LoadAndBootWindows(), LoadAndBootWindowsCommon(), LoadReactOSSetup(), LoadWindowsCore(), NtLdrGetOption(), and RamDiskInitialize().

◆ NtLdrGetOptionExN()

PCSTR NtLdrGetOptionExN ( _In_ PCSTR  Options,
_In_reads_(OptNameLength) PCCH  OptionName,
_In_ ULONG  OptNameLength,
_Out_opt_ PULONG  OptionLength 
)

Definition at line 73 of file ntldropts.c.

78{
79 PCSTR NextOptions;
80 PCSTR Option = NULL;
81 ULONG OptLength = 0;
82
83 if (OptionLength)
84 *OptionLength = 0;
85
86 if (!Options || !*Options)
87 return NULL;
88 if (!OptionName || (OptNameLength == 0) || !*OptionName)
89 return NULL;
90
91 NextOptions = Options;
92 while ((Option = NtLdrGetNextOption(&NextOptions, &OptLength)))
93 {
94 /*
95 * Check whether the option to find exactly matches the current
96 * load option, or is a prefix thereof if this is an option with
97 * appended data.
98 */
99 if ((OptLength >= OptNameLength) &&
100 (_strnicmp(Option, OptionName, OptNameLength) == 0))
101 {
102 if ((OptLength == OptNameLength) ||
103 (OptionName[OptNameLength-1] == '=') ||
104 (OptionName[OptNameLength-1] == ':'))
105 {
106 break;
107 }
108 }
109 }
110
111 if (Option && OptionLength)
112 *OptionLength = OptLength;
113 return Option;
114}
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
PCSTR NtLdrGetNextOption(_Inout_ PCSTR *Options, _Out_opt_ PULONG OptionLength)
Definition: ntldropts.c:18

Referenced by NtLdrGetHigherPriorityOptions(), and NtLdrGetOptionEx().

◆ NtLdrUpdateOptions()

VOID NtLdrUpdateOptions ( _Inout_updates_z_(BufferSize) PSTR  LoadOptions,
_In_ ULONG  BufferSize,
_In_ BOOLEAN  Append,
_In_opt_ PCSTR  OptionsToAdd[],
_In_opt_ PCSTR  OptionsToRemove[] 
)

Updates the options in the buffer pointed by LoadOptions, of maximum size BufferSize, by first removing any specified options, and then adding any other ones.

OptionsToAdd is a NULL-terminated array of string buffer pointers that specify the options to be added into LoadOptions. Whether they are prepended or appended to LoadOptions is controlled via the Append parameter. The options are added in the order specified by the array.

OptionsToRemove is a NULL-terminated array of string buffer pointers that specify the options to remove from LoadOptions. Specifying also there any options to add, has the effect of removing from LoadOptions any duplicates of the options to be added, before adding them later into LoadOptions. The options are removed in the order specified by the array.

The options string buffers in the OptionsToRemove array have the format: "/option1 /option2[=] ..."

An option in the OptionsToRemove list with a trailing '=' or ':' designates an option in LoadOptions with user-specific data appended after the sign. When such an option is being removed from LoadOptions, all the appended data is also removed until the next option.

Definition at line 244 of file ntldropts.c.

250{
251 PCSTR NextOptions, NextOpt;
252 PSTR Options, Option;
253 ULONG NextOptLength;
254 ULONG OptionLength;
255
256 if (!LoadOptions || (BufferSize == 0))
257 return;
258 // ASSERT(strlen(LoadOptions) + 1 <= BufferSize);
259
260 /* Loop over the options to remove */
261 for (; OptionsToRemove && *OptionsToRemove; ++OptionsToRemove)
262 {
263 NextOptions = *OptionsToRemove;
264 while ((NextOpt = NtLdrGetNextOption(&NextOptions, &NextOptLength)))
265 {
266 /* Scan the load options */
267 Options = LoadOptions;
268 while ((Option = (PSTR)NtLdrGetNextOption((PCSTR*)&Options, &OptionLength)))
269 {
270 /*
271 * Check whether the option to find exactly matches the current
272 * load option, or is a prefix thereof if this is an option with
273 * appended data.
274 */
275 if ((OptionLength >= NextOptLength) &&
276 (_strnicmp(Option, NextOpt, NextOptLength) == 0))
277 {
278 if ((OptionLength == NextOptLength) ||
279 (NextOpt[NextOptLength-1] == '=') ||
280 (NextOpt[NextOptLength-1] == ':'))
281 {
282 /* Eat any skipped option or whitespace separators */
283 while ((Option > LoadOptions) &&
284 (Option[-1] == '/' ||
285 Option[-1] == ' ' ||
286 Option[-1] == '\t'))
287 {
288 --Option;
289 }
290
291 /* If the option was not preceded by a whitespace
292 * separator, insert one and advance the pointer. */
293 if ((Option > LoadOptions) &&
294 (Option[-1] != ' ') &&
295 (Option[-1] != '\t') &&
296 (*Options != '\0') /* &&
297 ** Not necessary since NtLdrGetNextOption() **
298 ** stripped any leading separators. **
299 (*Options != ' ') &&
300 (*Options != '\t') */)
301 {
302 *Option++ = ' ';
303 }
304
305 /* Move the remaining options back, erasing the current one */
306 ASSERT(Option <= Options);
307 RtlMoveMemory(Option,
308 Options,
309 (strlen(Options) + 1) * sizeof(CHAR));
310
311 /* Reset the iterator */
312 Options = Option;
313 }
314 }
315 }
316 }
317 }
318
319 /* Now loop over the options to add */
320 for (; OptionsToAdd && *OptionsToAdd; ++OptionsToAdd)
321 {
322 NtLdrAddOptions(LoadOptions,
324 Append,
325 *OptionsToAdd);
326 }
327}
#define ASSERT(a)
Definition: mode.c:44
VOID NtLdrAddOptions(_Inout_updates_z_(BufferSize) PSTR Options, _In_ ULONG BufferSize, _In_ BOOLEAN Append, _In_opt_ PCSTR NewOptions)
Appends or prepends new options to the ones originally contained in the buffer pointed by Options,...
Definition: ntldropts.c:141
char * PSTR
Definition: typedefs.h:51

Referenced by AppendBootTimeOptions(), and LoadReactOSSetup().