4 * Copyright (C) 2009 Aleksey Bragin <aleksey@reactos.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <ndk/ldrtypes.h>
25 #include <arc/setupblk.h>
29 DBG_DEFAULT_CHANNEL(WINDOWS
);
30 #define TAG_BOOT_OPTIONS 'pOtB'
33 VOID
AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK
*OutLoaderBlock
);
36 SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock
, HINF InfHandle
, LPCSTR SearchPath
)
38 INFCONTEXT InfContext
;
40 LPCSTR AnsiName
, OemName
, LangName
;
42 /* Get ANSI codepage file */
43 if (!InfFindFirstLine(InfHandle
, "NLS", "AnsiCodepage", &InfContext
))
45 ERR("Failed to find 'NLS/AnsiCodepage'\n");
48 if (!InfGetDataField(&InfContext
, 1, &AnsiName
))
50 ERR("Failed to get load options\n");
54 /* Get OEM codepage file */
55 if (!InfFindFirstLine(InfHandle
, "NLS", "OemCodepage", &InfContext
))
57 ERR("Failed to find 'NLS/AnsiCodepage'\n");
60 if (!InfGetDataField(&InfContext
, 1, &OemName
))
62 ERR("Failed to get load options\n");
66 if (!InfFindFirstLine(InfHandle
, "NLS", "UnicodeCasetable", &InfContext
))
68 ERR("Failed to find 'NLS/AnsiCodepage'\n");
71 if (!InfGetDataField(&InfContext
, 1, &LangName
))
73 ERR("Failed to get load options\n");
77 Success
= WinLdrLoadNLSData(LoaderBlock
, SearchPath
, AnsiName
, OemName
, LangName
);
78 TRACE("NLS data loading %s\n", Success
? "successful" : "failed");
82 SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead
, HINF InfHandle
, LPCSTR SearchPath
)
84 INFCONTEXT InfContext
, dirContext
;
86 LPCSTR Media
, DriverName
, dirIndex
, ImagePath
;
87 WCHAR ServiceName
[256];
88 WCHAR ImagePathW
[256];
90 /* Open inf section */
91 if (!InfFindFirstLine(InfHandle
, "SourceDisksFiles", NULL
, &InfContext
))
94 /* Load all listed boot drivers */
97 if (InfGetDataField(&InfContext
, 7, &Media
) &&
98 InfGetDataField(&InfContext
, 0, &DriverName
) &&
99 InfGetDataField(&InfContext
, 13, &dirIndex
))
101 if ((strcmp(Media
, "x") == 0) &&
102 InfFindFirstLine(InfHandle
, "Directories", dirIndex
, &dirContext
) &&
103 InfGetDataField(&dirContext
, 1, &ImagePath
))
105 /* Convert name to widechar */
106 swprintf(ServiceName
, L
"%S", DriverName
);
108 /* Prepare image path */
109 swprintf(ImagePathW
, L
"%S", ImagePath
);
110 wcscat(ImagePathW
, L
"\\");
111 wcscat(ImagePathW
, ServiceName
);
113 /* Remove .sys extension */
114 ServiceName
[wcslen(ServiceName
) - 4] = 0;
116 /* Add it to the list */
117 Success
= WinLdrAddDriverToList(BootDriverListHead
,
118 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
123 ERR("could not add boot driver %s, %s\n", SearchPath
, DriverName
);
128 } while (InfFindNextLine(&InfContext
, &InfContext
));
132 LoadReactOSSetup(IN OperatingSystemItem
* OperatingSystem
,
133 IN USHORT OperatingSystemVersion
)
136 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
137 CHAR SettingsValue
[80];
139 CHAR BootOptions2
[256];
145 BOOLEAN BootFromFloppy
;
148 INFCONTEXT InfContext
;
149 PLOADER_PARAMETER_BLOCK LoaderBlock
;
150 PSETUP_LOADER_BLOCK SetupBlock
;
152 LPCSTR SourcePaths
[] =
154 "", /* Only for floppy boot */
157 #elif defined(_M_MPPC)
159 #elif defined(_M_MRX000)
166 /* Get OS setting value */
167 SettingsValue
[0] = ANSI_NULL
;
168 IniOpenSection("Operating Systems", &SectionId
);
169 IniReadSettingByName(SectionId
, SectionName
, SettingsValue
, sizeof(SettingsValue
));
171 /* Open the operating system section specified in the .ini file */
172 HasSection
= IniOpenSection(SectionName
, &SectionId
);
175 UiDrawProgressBarCenter(1, 100, "Loading ReactOS Setup...");
177 /* Read the system path is set in the .ini file */
179 !IniReadSettingByName(SectionId
, "SystemPath", BootPath
, sizeof(BootPath
)))
182 * IMPROVE: I don't want to call MachDiskGetBootPath here as a
183 * default choice because I can call it after (see few lines below).
184 * Also doing the strcpy call as it is done in winldr.c is not
185 * really what we want. Instead I reset BootPath here so that
186 * we can build the full path using the general code from below.
188 // MachDiskGetBootPath(BootPath, sizeof(BootPath));
189 // strcpy(BootPath, SectionName);
194 * Check whether BootPath is a full path
195 * and if not, create a full boot path.
197 * See FsOpenFile for the technique used.
199 if (strrchr(BootPath
, ')') == NULL
)
201 /* Temporarily save the boot path */
202 strcpy(FileName
, BootPath
);
204 /* This is not a full path. Use the current (i.e. boot) device. */
205 MachDiskGetBootPath(BootPath
, sizeof(BootPath
));
207 /* Append a path separator if needed */
208 if (FileName
[0] != '\\' && FileName
[0] != '/')
209 strcat(BootPath
, "\\");
211 /* Append the remaining path */
212 strcat(BootPath
, FileName
);
215 /* Append a backslash if needed */
216 if ((strlen(BootPath
) == 0) || BootPath
[strlen(BootPath
) - 1] != '\\')
217 strcat(BootPath
, "\\");
219 /* Read booting options */
220 if (!HasSection
|| !IniReadSettingByName(SectionId
, "Options", BootOptions2
, sizeof(BootOptions2
)))
222 /* Get options after the title */
223 PCSTR p
= SettingsValue
;
224 while (*p
== ' ' || *p
== '"')
226 while (*p
!= '\0' && *p
!= '"')
228 strcpy(BootOptions2
, p
);
229 TRACE("BootOptions: '%s'\n", BootOptions2
);
232 /* Check if a ramdisk file was given */
233 File
= strstr(BootOptions2
, "/RDPATH=");
236 /* Copy the file name and everything else after it */
237 strcpy(FileName
, File
+ 8);
240 *strstr(FileName
, " ") = ANSI_NULL
;
242 /* Load the ramdisk */
243 if (!RamDiskLoadVirtualFile(FileName
))
245 UiMessageBox("Failed to load RAM disk file %s", FileName
);
250 TRACE("BootPath: '%s'\n", BootPath
);
252 /* And check if we booted from floppy */
253 BootFromFloppy
= strstr(BootPath
, "fdisk") != NULL
;
255 /* Open 'txtsetup.sif' from any of source paths */
256 File
= BootPath
+ strlen(BootPath
);
257 for (i
= BootFromFloppy
? 0 : 1; ; i
++)
259 SystemPath
= SourcePaths
[i
];
262 UiMessageBox("Failed to open txtsetup.sif");
265 strcpy(File
, SystemPath
);
266 strcpy(FileName
, BootPath
);
267 strcat(FileName
, "txtsetup.sif");
268 if (InfOpenFile(&InfHandle
, FileName
, &ErrorLine
))
274 TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath
, SystemPath
);
276 /* Get Load options - debug and non-debug */
277 if (!InfFindFirstLine(InfHandle
, "SetupData", "OsLoadOptions", &InfContext
))
279 ERR("Failed to find 'SetupData/OsLoadOptions'\n");
283 if (!InfGetDataField(&InfContext
, 1, &LoadOptions
))
285 ERR("Failed to get load options\n");
290 /* Get debug load options and use them */
291 if (InfFindFirstLine(InfHandle
, "SetupData", "DbgOsLoadOptions", &InfContext
))
293 LPCSTR DbgLoadOptions
;
295 if (InfGetDataField(&InfContext
, 1, &DbgLoadOptions
))
296 LoadOptions
= DbgLoadOptions
;
300 /* Copy loadoptions (original string will be freed) */
301 BootOptions
= FrLdrTempAlloc(strlen(LoadOptions
) + 1, TAG_BOOT_OPTIONS
);
302 strcpy(BootOptions
, LoadOptions
);
304 TRACE("BootOptions: '%s'\n", BootOptions
);
306 UiDrawStatusText("Setup is loading...");
308 /* Allocate and minimalist-initialize LPB */
309 AllocateAndInitLPB(&LoaderBlock
);
311 /* Allocate and initialize setup loader block */
312 SetupBlock
= &WinLdrSystemBlock
->SetupBlock
;
313 LoaderBlock
->SetupLdrBlock
= SetupBlock
;
315 /* Set textmode setup flag */
316 SetupBlock
->Flags
= SETUPLDR_TEXT_MODE
;
318 /* Load NLS data, they are in system32 */
319 strcpy(FileName
, BootPath
);
320 strcat(FileName
, "system32\\");
321 SetupLdrLoadNlsData(LoaderBlock
, InfHandle
, FileName
);
323 /* Get a list of boot drivers */
324 SetupLdrScanBootDrivers(&LoaderBlock
->BootDriverListHead
, InfHandle
, BootPath
);
326 /* Close the inf file */
327 InfCloseFile(InfHandle
);
329 /* Load ReactOS Setup */
330 LoadAndBootWindowsCommon(_WIN32_WINNT_WS03
,