ReactOS 0.4.17-dev-116-ga4b6fe9
oslist.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tagOperatingSystemItem
 

Macros

#define TAG_STRING   ' rtS'
 

Typedefs

typedef struct tagOperatingSystemItem OperatingSystemItem
 

Functions

OperatingSystemItemInitOperatingSystemList (_Out_ PULONG OperatingSystemCount, _Out_ PULONG DefaultOperatingSystem)
 

Macro Definition Documentation

◆ TAG_STRING

#define TAG_STRING   ' rtS'

Definition at line 22 of file oslist.h.

Typedef Documentation

◆ OperatingSystemItem

Function Documentation

◆ InitOperatingSystemList()

OperatingSystemItem * InitOperatingSystemList ( _Out_ PULONG  OperatingSystemCount,
_Out_ PULONG  DefaultOperatingSystem 
)

Definition at line 46 of file oslist.c.

49{
51 PCSTR DefaultOSName;
52 ULONG DefaultOS = 0;
54 ULONG i;
55 ULONG_PTR OsSectionId, SectionId;
56 PCHAR TitleStart, TitleEnd;
57 PCSTR OsLoadOptions;
58 BOOLEAN HadSection;
59 BOOLEAN HadNoBootType;
60 CHAR SettingName[260];
61 CHAR SettingValue[260];
62 CHAR BootType[80];
63 CHAR TempBuffer[_countof(SettingValue)];
64
65 /* Default with an empty list */
66 *OperatingSystemCount = 0;
67
68 /* Open the [Operating Systems] section */
69 if (!IniOpenSection("Operating Systems", &OsSectionId))
70 {
71 UiMessageBox("Operating Systems section not found in freeldr.ini");
72 return NULL;
73 }
74
75 /* Count the number of operating systems in the section */
76 Count = IniGetNumSectionItems(OsSectionId);
77 if (Count == 0) /* Fail if no operating systems are found */
78 return NULL;
79
80 /* Allocate memory to hold operating system lists */
82 if (!Items)
83 return NULL;
84
85 /* Retrieve the default OS */
86 DefaultOSName = GetBootMgrInfo()->DefaultOs;
87
88 /* Now loop through the operating system section and load each item */
89 for (i = 0; i < Count; ++i)
90 {
91 IniReadSettingByNumber(OsSectionId, i,
92 SettingName, sizeof(SettingName),
93 SettingValue, sizeof(SettingValue));
94 if (!*SettingName)
95 {
96 TRACE("Unkeyed OS entry %lu: separator.\n", i);
97 continue;
98 }
99
100 /* Retrieve the start and end of the title */
101 TitleStart = SettingValue;
102 /* Trim any leading whitespace and quotes */
103 while (*TitleStart == ' ' || *TitleStart == '\t' || *TitleStart == '"')
104 ++TitleStart;
105 TitleEnd = TitleStart;
106 /* Go up to the first last quote */
107 while (*TitleEnd != ANSI_NULL && *TitleEnd != '"')
108 ++TitleEnd;
109
110 /* NULL-terminate the title */
111 if (*TitleEnd)
112 *TitleEnd++ = ANSI_NULL; // Skip the quote too.
113
114 /* Retrieve the options after the quoted title */
115 if (*TitleEnd)
116 {
117 /* Trim any trailing whitespace and quotes */
118 while (*TitleEnd == ' ' || *TitleEnd == '\t' || *TitleEnd == '"')
119 ++TitleEnd;
120 }
121 OsLoadOptions = (*TitleEnd ? TitleEnd : NULL);
122
123 // TRACE("\n"
124 // "SettingName = '%s'\n"
125 // "TitleStart = '%s'\n"
126 // "OsLoadOptions = '%s'\n",
127 // SettingName, TitleStart, OsLoadOptions);
128
129 /* Find the default OS item while we haven't got one */
130 if (DefaultOSName && _stricmp(DefaultOSName, SettingName) == 0)
131 {
132 DefaultOS = i;
133 DefaultOSName = NULL; // We have found the first one, don't search for others.
134 }
135
136 /*
137 * Determine whether this is a legacy operating system entry of the form:
138 *
139 * [Operating Systems]
140 * ArcOsLoadPartition="LoadIdentifier" /List /of /Options
141 *
142 * and if so, convert it into a new operating system INI entry:
143 *
144 * [Operating Systems]
145 * SectionIdentifier="LoadIdentifier"
146 *
147 * [SectionIdentifier]
148 * BootType=...
149 * SystemPath=ArcOsLoadPartition
150 * Options=/List /of /Options
151 *
152 * The "BootType" value is heuristically determined from the form of
153 * the ArcOsLoadPartition: if this is an ARC path, the "BootType" value
154 * is "Windows", otherwise if this is a DOS path the "BootType" value
155 * is "BootSector". This ensures backwards-compatibility with NTLDR.
156 */
157
158 /* Try to open the operating system section in the .ini file */
159 SectionId = 0;
160 HadSection = IniOpenSection(SettingName, &SectionId);
161 if (HadSection)
162 {
163 /* This is a new OS entry: try to read the boot type */
164 *BootType = ANSI_NULL;
165 IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
166 }
167 else
168 {
169 /* This is a legacy OS entry: no explicit BootType specified, we will infer one */
170 *BootType = ANSI_NULL;
171 }
172
173 /* Check whether we have got a BootType value; if not, try to infer one */
174 HadNoBootType = (*BootType == ANSI_NULL);
175 if (HadNoBootType)
176 {
177#ifdef _M_IX86
178 ULONG FileId;
179 if (ArcOpen(SettingName, OpenReadOnly, &FileId) == ESUCCESS)
180 {
181 ArcClose(FileId);
182 strcpy(BootType, "BootSector");
183 }
184 else
185#endif
186 {
187 strcpy(BootType, "Windows");
188 }
189 }
190
191 /* This is a legacy OS entry: convert it into a new OS entry */
192 if (!HadSection)
193 {
194 TIMEINFO* TimeInfo;
195
196 /* Save the system path from the original SettingName (overwritten below) */
197 RtlStringCbCopyA(TempBuffer, sizeof(TempBuffer), SettingName);
198
199 /* Generate a unique section name */
200 TimeInfo = ArcGetTime();
201 if (_stricmp(BootType, "BootSector") == 0)
202 {
203 RtlStringCbPrintfA(SettingName, sizeof(SettingName),
204 "BootSectorFile%u%u%u%u%u%u",
205 TimeInfo->Year, TimeInfo->Day, TimeInfo->Month,
206 TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
207 }
208 else if (_stricmp(BootType, "Windows") == 0)
209 {
210 RtlStringCbPrintfA(SettingName, sizeof(SettingName),
211 "Windows%u%u%u%u%u%u",
212 TimeInfo->Year, TimeInfo->Day, TimeInfo->Month,
213 TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
214 }
215 else
216 {
217 ASSERT(FALSE);
218 }
219
220 /* Add the section */
221 if (!IniAddSection(SettingName, &SectionId))
222 {
223 ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
224 continue;
225 }
226
227 /* Add the system path */
228 if (_stricmp(BootType, "BootSector") == 0)
229 {
230 if (!IniAddSettingValueToSection(SectionId, "BootSectorFile", TempBuffer))
231 {
232 ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
233 continue;
234 }
235 }
236 else if (_stricmp(BootType, "Windows") == 0)
237 {
238 if (!IniAddSettingValueToSection(SectionId, "SystemPath", TempBuffer))
239 {
240 ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
241 continue;
242 }
243 }
244 else
245 {
246 ASSERT(FALSE);
247 }
248
249 /* Add the OS options */
250 if (OsLoadOptions && !IniAddSettingValueToSection(SectionId, "Options", OsLoadOptions))
251 {
252 ERR("Could not convert legacy OS entry %lu, skipping.\n", i);
253 continue;
254 }
255 }
256
257 /* Add or modify the BootType if needed */
258 if (HadNoBootType && !IniModifySettingValue(SectionId, "BootType", BootType))
259 {
260 ERR("Could not fixup the BootType entry for OS '%s', ignoring.\n", SettingName);
261 }
262
263 /*
264 * If this is a new OS entry, but some options were given appended to
265 * the OS entry item, append them instead to the "Options=" value.
266 */
267 if (HadSection && OsLoadOptions && *OsLoadOptions)
268 {
269 /* Read the original "Options=" value */
270 *TempBuffer = ANSI_NULL;
271 if (!IniReadSettingByName(SectionId, "Options", TempBuffer, sizeof(TempBuffer)))
272 TRACE("No 'Options' value found for OS '%s', ignoring.\n", SettingName);
273
274 /* Concatenate the options together */
275 RtlStringCbCatA(TempBuffer, sizeof(TempBuffer), " ");
276 RtlStringCbCatA(TempBuffer, sizeof(TempBuffer), OsLoadOptions);
277
278 /* Save them */
279 if (!IniModifySettingValue(SectionId, "Options", TempBuffer))
280 ERR("Could not modify the options for OS '%s', ignoring.\n", SettingName);
281 }
282
283 /* Copy the OS section ID and its identifier */
284 Items[i].SectionId = SectionId;
285 Items[i].LoadIdentifier = CopyString(TitleStart);
286 // TRACE("We did Items[%lu]: SectionName = '%s' (SectionId = 0x%p), LoadIdentifier = '%s'\n",
287 // i, SettingName, Items[i].SectionId, Items[i].LoadIdentifier);
288 }
289
290 /* Return success */
291 *OperatingSystemCount = Count;
292 *DefaultOperatingSystem = DefaultOS;
293 return Items;
294}
unsigned char BOOLEAN
Definition: actypes.h:127
TIMEINFO * ArcGetTime(VOID)
Definition: arcemul.c:27
#define ERR(fmt,...)
Definition: precomp.h:57
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:219
ARC_STATUS ArcClose(_In_ ULONG FileId)
Definition: fs.c:409
PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: heap.c:533
PBOOTMGRINFO GetBootMgrInfo(VOID)
Definition: settings.c:214
VOID UiMessageBox(_In_ PCSTR Format,...)
Definition: ui.c:359
#define _stricmp
Definition: cat.c:22
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
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
PINI_SECTION IniAddSection(_In_ PINICACHE Cache, _In_ PCWSTR Name)
Definition: inicache.c:838
ULONG IniGetNumSectionItems(ULONG_PTR SectionId)
Definition: inifile.c:60
BOOLEAN IniAddSettingValueToSection(ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
Definition: inifile.c:260
BOOLEAN IniModifySettingValue(ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
Definition: inifile.c:301
BOOLEAN IniReadSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize)
Definition: inifile.c:121
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:154
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:30
#define ASSERT(a)
Definition: mode.c:44
int Count
Definition: noreturn.cpp:7
#define ANSI_NULL
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
#define TAG_OS_ITEM
Definition: oslist.c:27
static PCSTR CopyString(PCSTR Source)
Definition: oslist.c:31
char CHAR
Definition: pedump.c:57
@ ESUCCESS
Definition: arc.h:32
@ OpenReadOnly
Definition: arc.h:65
strcpy
Definition: string.h:131
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
PCSTR DefaultOs
Definition: settings.h:14
Definition: fw.h:10
USHORT Month
Definition: fw.h:12
USHORT Day
Definition: fw.h:13
USHORT Minute
Definition: fw.h:15
USHORT Hour
Definition: fw.h:14
USHORT Second
Definition: fw.h:16
USHORT Year
Definition: fw.h:11
ULONG_PTR SectionId
Definition: oslist.h:26
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51

Referenced by RunLoader().