ReactOS  0.4.14-dev-52-g6116262
cmdline.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Boot Loader
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * FILE: boot/freeldr/freeldr/cmdline.c
5  * PURPOSE: FreeLDR Command Line Parsing
6  * PROGRAMMERS: ReactOS Portable Systems Group
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <freeldr.h>
12 
13 /* GLOBALS ********************************************************************/
14 
15 typedef struct tagCMDLINEINFO
16 {
21 
25 
26 /* FUNCTIONS ******************************************************************/
27 
28 VOID
30 {
31  PCHAR End, Setting;
32  ULONG_PTR Length, Offset = 0;
33 
34  /* Set defaults */
37  CmdLineInfo.TimeOut = -1;
38 
39  /*
40  * Get debug string, in the following format:
41  * "debug=option1=XXX;option2=YYY;..."
42  * and translate it into the format:
43  * "OPTION1=XXX OPTION2=YYY ..."
44  */
45  Setting = strstr(CmdLine, "debug=");
46  if (Setting)
47  {
48  /* Check if there are more command-line parameters following */
49  Setting += sizeof("debug=") - sizeof(ANSI_NULL);
50  End = strstr(Setting, " ");
51  Length = (End ? (End - Setting) : strlen(Setting));
52 
53  /* Copy the debug string and upcase it */
54  RtlStringCbCopyNA(DebugString, sizeof(DebugString), Setting, Length);
56 
57  /* Replace all separators ';' by spaces */
58  Setting = DebugString;
59  while (*Setting)
60  {
61  if (*Setting == ';') *Setting = ' ';
62  Setting++;
63  }
64 
66  }
67 
68  /* Get timeout */
69  Setting = strstr(CmdLine, "timeout=");
70  if (Setting)
71  {
72  CmdLineInfo.TimeOut = atoi(Setting +
73  sizeof("timeout=") - sizeof(ANSI_NULL));
74  }
75 
76  /* Get default OS */
77  Setting = strstr(CmdLine, "defaultos=");
78  if (Setting)
79  {
80  /* Check if there are more command-line parameters following */
81  Setting += sizeof("defaultos=") - sizeof(ANSI_NULL);
82  End = strstr(Setting, " ");
83  Length = (End ? (End - Setting) : strlen(Setting));
84 
85  /* Copy the default OS */
86  RtlStringCbCopyNA(DefaultOs, sizeof(DefaultOs), Setting, Length);
88  }
89 
90  /* Get ramdisk base address */
91  Setting = strstr(CmdLine, "rdbase=");
92  if (Setting)
93  {
95  (PVOID)(ULONG_PTR)strtoull(Setting +
96  sizeof("rdbase=") - sizeof(ANSI_NULL),
97  NULL, 0);
98  }
99 
100  /* Get ramdisk size */
101  Setting = strstr(CmdLine, "rdsize=");
102  if (Setting)
103  {
104  gInitRamDiskSize = strtoul(Setting +
105  sizeof("rdsize=") - sizeof(ANSI_NULL),
106  NULL, 0);
107  }
108 
109  /* Get ramdisk offset */
110  Setting = strstr(CmdLine, "rdoffset=");
111  if (Setting)
112  {
113  Offset = strtoul(Setting +
114  sizeof("rdoffset=") - sizeof(ANSI_NULL),
115  NULL, 0);
116  }
117 
118  /* Fix it up */
120 }
121 
122 PCSTR
124 {
125  return CmdLineInfo.DebugString;
126 }
127 
128 PCSTR
130 {
131  return CmdLineInfo.DefaultOs;
132 }
133 
134 LONG
136 {
137  return CmdLineInfo.TimeOut;
138 }
signed char * PCHAR
Definition: retypes.h:7
#define IN
Definition: typedefs.h:38
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
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
PCSTR CmdLineGetDebugString(VOID)
Definition: cmdline.c:123
LONG CmdLineGetTimeOut(VOID)
Definition: cmdline.c:135
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
PCSTR CmdLineGetDefaultOS(VOID)
Definition: cmdline.c:129
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define ANSI_NULL
long LONG
Definition: pedump.c:60
VOID CmdLineParse(IN PCSTR CmdLine)
Definition: cmdline.c:29
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
struct tagCMDLINEINFO CMDLINEINFO
CMDLINEINFO CmdLineInfo
Definition: cmdline.c:24
#define strtoull
Definition: stabs.c:72
LONG TimeOut
Definition: cmdline.c:19
char CCHAR
Definition: typedefs.h:50
ULONG gInitRamDiskSize
Definition: ramdisk.c:17
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
CHAR CmdLine[MAX_PATH]
Definition: mach.c:34
struct tagCMDLINEINFO * PCMDLINEINFO
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
CCHAR DefaultOs[256]
Definition: cmdline.c:23
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
CCHAR DebugString[256]
Definition: cmdline.c:22
const char * PCSTR
Definition: typedefs.h:51
PCSTR DefaultOs
Definition: cmdline.c:18
PVOID gInitRamDiskBase
Definition: ramdisk.c:16
PCSTR DebugString
Definition: cmdline.c:17