3 * Copyright (C) 2002 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: subsys/system/usetup/bootsup.c
23 * PURPOSE: Bootloader support functions
24 * PROGRAMMER: Eric Kohl
28 #include <ntdll/rtl.h>
38 #define SECTORSIZE 512
40 /* FUNCTIONS ****************************************************************/
44 CreateCommonFreeLoaderSections(PINICACHE IniCache
)
46 PINICACHESECTION IniSection
;
48 /* Create "FREELOADER" section */
49 IniSection
= IniCacheAppendSection(IniCache
,
52 /* DefaultOS=ReactOS */
53 IniCacheInsertKey(IniSection
,
61 IniCacheInsertKey(IniSection
,
68 /* Create "Display" section */
69 IniSection
= IniCacheAppendSection(IniCache
,
72 /* TitleText=ReactOS Boot Manager */
73 IniCacheInsertKey(IniSection
,
77 L
"ReactOS Boot Manager");
79 /* StatusBarColor=Cyan */
80 IniCacheInsertKey(IniSection
,
86 /* StatusBarTextColor=Black */
87 IniCacheInsertKey(IniSection
,
90 L
"StatusBarTextColor",
93 /* BackdropTextColor=White */
94 IniCacheInsertKey(IniSection
,
100 /* BackdropColor=Blue */
101 IniCacheInsertKey(IniSection
,
107 /* BackdropFillStyle=Medium */
108 IniCacheInsertKey(IniSection
,
111 L
"BackdropFillStyle",
114 /* TitleBoxTextColor=White */
115 IniCacheInsertKey(IniSection
,
118 L
"TitleBoxTextColor",
121 /* TitleBoxColor=Red */
122 IniCacheInsertKey(IniSection
,
128 /* MessageBoxTextColor=White */
129 IniCacheInsertKey(IniSection
,
132 L
"MessageBoxTextColor",
135 /* MessageBoxColor=Blue */
136 IniCacheInsertKey(IniSection
,
142 /* MenuTextColor=White */
143 IniCacheInsertKey(IniSection
,
150 IniCacheInsertKey(IniSection
,
156 /* TextColor=Yellow */
157 IniCacheInsertKey(IniSection
,
163 /* SelectedTextColor=Black */
164 IniCacheInsertKey(IniSection
,
167 L
"SelectedTextColor",
170 /* SelectedColor=Gray */
171 IniCacheInsertKey(IniSection
,
178 IniCacheInsertKey(IniSection
,
187 CreateFreeLoaderIniForDos(PWCHAR IniPath
,
191 PINICACHESECTION IniSection
;
193 IniCache
= IniCacheCreate();
195 CreateCommonFreeLoaderSections(IniCache
);
197 /* Create "Operating Systems" section */
198 IniSection
= IniCacheAppendSection(IniCache
,
199 L
"Operating Systems");
201 /* REACTOS=ReactOS */
202 IniCacheInsertKey(IniSection
,
208 /* ReactOS_Debug="ReactOS (Debug)" */
209 IniCacheInsertKey(IniSection
,
213 L
"\"ReactOS (Debug)\"");
215 /* DOS=Dos/Windows */
216 IniCacheInsertKey(IniSection
,
222 /* Create "ReactOS" section */
223 IniSection
= IniCacheAppendSection(IniCache
,
226 /* BootType=ReactOS */
227 IniCacheInsertKey(IniSection
,
233 /* SystemPath=<ArcPath> */
234 IniCacheInsertKey(IniSection
,
240 /* Create "ReactOS_Debug" section */
241 IniSection
= IniCacheAppendSection(IniCache
,
244 /* BootType=ReactOS */
245 IniCacheInsertKey(IniSection
,
251 /* SystemPath=<ArcPath> */
252 IniCacheInsertKey(IniSection
,
258 /* Options=/DEBUGPORT=SCREEN /NOGUIBOOT */
259 IniCacheInsertKey(IniSection
,
263 L
"/DEBUGPORT=SCREEN /NOGUIBOOT");
265 /* Create "DOS" section */
266 IniSection
= IniCacheAppendSection(IniCache
,
269 /* BootType=BootSector */
270 IniCacheInsertKey(IniSection
,
277 IniCacheInsertKey(IniSection
,
283 /* BootPartition=1 */
284 IniCacheInsertKey(IniSection
,
290 /* BootSector=BOOTSECT.DOS */
291 IniCacheInsertKey(IniSection
,
297 IniCacheSave(IniCache
, IniPath
);
298 IniCacheDestroy(IniCache
);
300 return(STATUS_SUCCESS
);
305 CreateFreeLoaderIniForReactos(PWCHAR IniPath
,
309 PINICACHESECTION IniSection
;
311 IniCache
= IniCacheCreate();
313 CreateCommonFreeLoaderSections(IniCache
);
315 /* Create "Operating Systems" section */
316 IniSection
= IniCacheAppendSection(IniCache
,
317 L
"Operating Systems");
319 /* ReactOS="ReactOS" */
320 IniCacheInsertKey(IniSection
,
326 /* ReactOS_Debug="ReactOS (Debug)" */
327 IniCacheInsertKey(IniSection
,
331 L
"\"ReactOS (Debug)\"");
333 /* Create "ReactOS" section */
334 IniSection
= IniCacheAppendSection(IniCache
,
337 /* BootType=ReactOS */
338 IniCacheInsertKey(IniSection
,
344 /* SystemPath=<ArcPath> */
345 IniCacheInsertKey(IniSection
,
351 /* Create "ReactOS_Debug" section */
352 IniSection
= IniCacheAppendSection(IniCache
,
355 /* BootType=ReactOS */
356 IniCacheInsertKey(IniSection
,
362 /* SystemPath=<ArcPath> */
363 IniCacheInsertKey(IniSection
,
369 /* Options=/DEBUGPORT=SCREEN /NOGUIBOOT */
370 IniCacheInsertKey(IniSection
,
374 L
"/DEBUGPORT=SCREEN /NOGUIBOOT");
376 /* Save the ini file */
377 IniCacheSave(IniCache
, IniPath
);
378 IniCacheDestroy(IniCache
);
380 return(STATUS_SUCCESS
);
385 UpdateFreeLoaderIni(PWCHAR IniPath
,
390 PINICACHESECTION IniSection
;
391 PINICACHESECTION OsIniSection
;
392 WCHAR SectionName
[80];
394 WCHAR SystemPath
[200];
395 WCHAR SectionName2
[200];
400 RtlInitUnicodeString(&Name
,
403 Status
= IniCacheLoad(&IniCache
,
406 if (!NT_SUCCESS(Status
))
409 /* Get "Operating Systems" section */
410 IniSection
= IniCacheGetSection(IniCache
,
411 L
"Operating Systems");
412 if (IniSection
== NULL
)
414 IniCacheDestroy(IniCache
);
415 return(STATUS_UNSUCCESSFUL
);
418 /* Find an existing usable or an unused section name */
420 wcscpy(SectionName
, L
"ReactOS");
421 wcscpy(OsName
, L
"\"ReactOS\"");
424 Status
= IniCacheGetKey(IniSection
,
427 if (!NT_SUCCESS(Status
))
430 /* Get operation system section */
431 if (KeyData
[0] == '"')
433 wcscpy(SectionName2
, &KeyData
[1]);
434 j
= wcslen(SectionName2
);
437 SectionName2
[j
-1] = 0;
442 wcscpy(SectionName2
, KeyData
);
445 OsIniSection
= IniCacheGetSection(IniCache
,
447 if (OsIniSection
!= NULL
)
449 BOOLEAN UseExistingEntry
= TRUE
;
452 Status
= IniCacheGetKey(OsIniSection
,
455 if (NT_SUCCESS(Status
))
458 || (_wcsicmp(KeyData
, L
"ReactOS") != 0
459 && _wcsicmp(KeyData
, L
"\"ReactOS\"") != 0))
461 /* This is not a ReactOS entry */
462 UseExistingEntry
= FALSE
;
467 UseExistingEntry
= FALSE
;
470 if (UseExistingEntry
)
472 /* BootType is ReactOS. Now check SystemPath */
473 Status
= IniCacheGetKey(OsIniSection
,
476 if (NT_SUCCESS(Status
))
478 swprintf(SystemPath
, L
"\"%S\"", ArcPath
);
480 || (_wcsicmp(KeyData
, ArcPath
) != 0
481 && _wcsicmp(KeyData
, SystemPath
) != 0))
483 /* This entry is a ReactOS entry, but the SystemRoot does not
484 match the one we are looking for */
485 UseExistingEntry
= FALSE
;
490 UseExistingEntry
= FALSE
;
494 if (UseExistingEntry
)
496 IniCacheDestroy(IniCache
);
497 return(STATUS_SUCCESS
);
501 swprintf(SectionName
, L
"ReactOS_%lu", i
);
502 swprintf(OsName
, L
"\"ReactOS %lu\"", i
);
506 /* <SectionName>=<OsName> */
507 IniCacheInsertKey(IniSection
,
513 /* Create <SectionName> section */
514 IniSection
= IniCacheAppendSection(IniCache
,
517 /* BootType=ReactOS */
518 IniCacheInsertKey(IniSection
,
524 /* SystemPath=<ArcPath> */
525 IniCacheInsertKey(IniSection
,
531 IniCacheSave(IniCache
, IniPath
);
532 IniCacheDestroy(IniCache
);
534 return(STATUS_SUCCESS
);
539 SaveCurrentBootSector(PWSTR RootPath
,
542 OBJECT_ATTRIBUTES ObjectAttributes
;
543 IO_STATUS_BLOCK IoStatusBlock
;
549 /* Allocate buffer for bootsector */
550 BootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
553 if (BootSector
== NULL
)
554 return(STATUS_INSUFFICIENT_RESOURCES
);
556 /* Read current boot sector into buffer */
557 RtlInitUnicodeString(&Name
,
560 InitializeObjectAttributes(&ObjectAttributes
,
562 OBJ_CASE_INSENSITIVE
,
566 Status
= NtOpenFile(&FileHandle
,
571 FILE_SYNCHRONOUS_IO_NONALERT
);
572 if (!NT_SUCCESS(Status
))
574 RtlFreeHeap(ProcessHeap
, 0, BootSector
);
578 Status
= NtReadFile(FileHandle
,
588 if (!NT_SUCCESS(Status
))
590 RtlFreeHeap(ProcessHeap
, 0, BootSector
);
594 /* Write bootsector to DstPath */
595 RtlInitUnicodeString(&Name
,
598 InitializeObjectAttributes(&ObjectAttributes
,
604 Status
= NtCreateFile(&FileHandle
,
609 FILE_ATTRIBUTE_NORMAL
,
612 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
,
615 if (!NT_SUCCESS(Status
))
617 RtlFreeHeap(ProcessHeap
, 0, BootSector
);
621 Status
= NtWriteFile(FileHandle
,
632 /* Free the new boot sector */
633 RtlFreeHeap(ProcessHeap
, 0, BootSector
);
640 InstallFat16BootCodeToFile(PWSTR SrcPath
,
644 OBJECT_ATTRIBUTES ObjectAttributes
;
645 IO_STATUS_BLOCK IoStatusBlock
;
649 PUCHAR OrigBootSector
;
650 PUCHAR NewBootSector
;
652 /* Allocate buffer for original bootsector */
653 OrigBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
656 if (OrigBootSector
== NULL
)
657 return(STATUS_INSUFFICIENT_RESOURCES
);
659 /* Read current boot sector into buffer */
660 RtlInitUnicodeString(&Name
,
663 InitializeObjectAttributes(&ObjectAttributes
,
665 OBJ_CASE_INSENSITIVE
,
669 Status
= NtOpenFile(&FileHandle
,
674 FILE_SYNCHRONOUS_IO_NONALERT
);
675 if (!NT_SUCCESS(Status
))
677 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
681 Status
= NtReadFile(FileHandle
,
691 if (!NT_SUCCESS(Status
))
693 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
698 /* Allocate buffer for new bootsector */
699 NewBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
702 if (NewBootSector
== NULL
)
704 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
705 return(STATUS_INSUFFICIENT_RESOURCES
);
708 /* Read new bootsector from SrcPath */
709 RtlInitUnicodeString(&Name
,
712 InitializeObjectAttributes(&ObjectAttributes
,
714 OBJ_CASE_INSENSITIVE
,
718 Status
= NtOpenFile(&FileHandle
,
723 FILE_SYNCHRONOUS_IO_NONALERT
);
724 if (!NT_SUCCESS(Status
))
726 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
727 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
731 Status
= NtReadFile(FileHandle
,
741 if (!NT_SUCCESS(Status
))
743 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
744 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
748 /* Adjust bootsector (copy a part of the FAT BPB) */
749 memcpy((NewBootSector
+ 11), (OrigBootSector
+ 11), 51 /*fat BPB length*/);
751 /* Free the original boot sector */
752 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
754 /* Write new bootsector to DstPath */
755 RtlInitUnicodeString(&Name
,
758 InitializeObjectAttributes(&ObjectAttributes
,
764 Status
= NtCreateFile(&FileHandle
,
769 FILE_ATTRIBUTE_NORMAL
,
772 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
,
775 if (!NT_SUCCESS(Status
))
777 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
782 FilePosition
.QuadPart
= 0;
784 Status
= NtWriteFile(FileHandle
,
795 /* Free the new boot sector */
796 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
803 InstallFat32BootCodeToFile(PWSTR SrcPath
,
807 OBJECT_ATTRIBUTES ObjectAttributes
;
808 IO_STATUS_BLOCK IoStatusBlock
;
812 PUCHAR OrigBootSector
;
813 PUCHAR NewBootSector
;
814 LARGE_INTEGER FileOffset
;
816 /* Allocate buffer for original bootsector */
817 OrigBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
820 if (OrigBootSector
== NULL
)
821 return(STATUS_INSUFFICIENT_RESOURCES
);
823 /* Read current boot sector into buffer */
824 RtlInitUnicodeString(&Name
,
827 InitializeObjectAttributes(&ObjectAttributes
,
829 OBJ_CASE_INSENSITIVE
,
833 Status
= NtOpenFile(&FileHandle
,
838 FILE_SYNCHRONOUS_IO_NONALERT
);
839 if (!NT_SUCCESS(Status
))
841 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
845 Status
= NtReadFile(FileHandle
,
855 if (!NT_SUCCESS(Status
))
858 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
862 /* Allocate buffer for new bootsector (2 sectors) */
863 NewBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
866 if (NewBootSector
== NULL
)
868 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
869 return(STATUS_INSUFFICIENT_RESOURCES
);
872 /* Read new bootsector from SrcPath */
873 RtlInitUnicodeString(&Name
,
876 InitializeObjectAttributes(&ObjectAttributes
,
878 OBJ_CASE_INSENSITIVE
,
882 Status
= NtOpenFile(&FileHandle
,
887 FILE_SYNCHRONOUS_IO_NONALERT
);
888 if (!NT_SUCCESS(Status
))
890 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
891 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
895 Status
= NtReadFile(FileHandle
,
905 if (!NT_SUCCESS(Status
))
907 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
908 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
912 /* Adjust bootsector (copy a part of the FAT32 BPB) */
913 memcpy((NewBootSector
+ 3),
914 (OrigBootSector
+ 3),
915 87); /* FAT32 BPB length */
917 /* Disable the backup boot sector */
918 NewBootSector
[0x32] = 0x00;
919 NewBootSector
[0x33] = 0x00;
921 /* Free the original boot sector */
922 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
924 /* Write the first sector of the new bootcode to DstPath */
925 RtlInitUnicodeString(&Name
,
928 InitializeObjectAttributes(&ObjectAttributes
,
934 Status
= NtCreateFile(&FileHandle
,
939 FILE_ATTRIBUTE_NORMAL
,
942 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
,
945 if (!NT_SUCCESS(Status
))
947 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
951 Status
= NtWriteFile(FileHandle
,
961 if (!NT_SUCCESS(Status
))
963 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
967 /* Write the second sector of the new bootcode to boot disk sector 14 */
968 RtlInitUnicodeString(&Name
,
971 InitializeObjectAttributes(&ObjectAttributes
,
977 Status
= NtOpenFile(&FileHandle
,
982 FILE_SYNCHRONOUS_IO_NONALERT
);
983 if (!NT_SUCCESS(Status
))
985 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
989 FileOffset
.QuadPart
= (ULONGLONG
)(14 * SECTORSIZE
);
990 Status
= NtWriteFile(FileHandle
,
995 (NewBootSector
+ SECTORSIZE
),
999 if (!NT_SUCCESS(Status
))
1002 NtClose(FileHandle
);
1004 /* Free the new boot sector */
1005 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1012 InstallMbrBootCodeToDisk (PWSTR SrcPath
,
1015 OBJECT_ATTRIBUTES ObjectAttributes
;
1016 IO_STATUS_BLOCK IoStatusBlock
;
1017 UNICODE_STRING Name
;
1020 PUCHAR OrigBootSector
;
1021 PUCHAR NewBootSector
;
1023 /* Allocate buffer for original bootsector */
1024 OrigBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1027 if (OrigBootSector
== NULL
)
1028 return(STATUS_INSUFFICIENT_RESOURCES
);
1030 /* Read current boot sector into buffer */
1031 RtlInitUnicodeString(&Name
,
1034 InitializeObjectAttributes(&ObjectAttributes
,
1036 OBJ_CASE_INSENSITIVE
,
1040 Status
= NtOpenFile(&FileHandle
,
1045 FILE_SYNCHRONOUS_IO_NONALERT
);
1046 if (!NT_SUCCESS(Status
))
1048 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1052 Status
= NtReadFile(FileHandle
,
1061 NtClose(FileHandle
);
1062 if (!NT_SUCCESS(Status
))
1064 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1069 /* Allocate buffer for new bootsector */
1070 NewBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1073 if (NewBootSector
== NULL
)
1075 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1076 return(STATUS_INSUFFICIENT_RESOURCES
);
1079 /* Read new bootsector from SrcPath */
1080 RtlInitUnicodeString(&Name
,
1083 InitializeObjectAttributes(&ObjectAttributes
,
1085 OBJ_CASE_INSENSITIVE
,
1089 Status
= NtOpenFile(&FileHandle
,
1094 FILE_SYNCHRONOUS_IO_NONALERT
);
1095 if (!NT_SUCCESS(Status
))
1097 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1098 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1102 Status
= NtReadFile(FileHandle
,
1111 NtClose(FileHandle
);
1112 if (!NT_SUCCESS(Status
))
1114 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1115 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1119 /* Copy partition table from old MBR to new */
1120 RtlCopyMemory ((NewBootSector
+ 446),
1121 (OrigBootSector
+ 446),
1122 4*16 /* Length of partition table */);
1124 /* Free the original boot sector */
1125 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1127 /* Write new bootsector to RootPath */
1128 RtlInitUnicodeString(&Name
,
1131 InitializeObjectAttributes(&ObjectAttributes
,
1137 Status
= NtOpenFile(&FileHandle
,
1142 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
);
1143 if (!NT_SUCCESS(Status
))
1145 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1146 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1150 Status
= NtWriteFile(FileHandle
,
1159 NtClose(FileHandle
);
1161 /* Free the new boot sector */
1162 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1169 InstallFat16BootCodeToDisk(PWSTR SrcPath
,
1172 OBJECT_ATTRIBUTES ObjectAttributes
;
1173 IO_STATUS_BLOCK IoStatusBlock
;
1174 UNICODE_STRING Name
;
1177 PUCHAR OrigBootSector
;
1178 PUCHAR NewBootSector
;
1180 /* Allocate buffer for original bootsector */
1181 OrigBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1184 if (OrigBootSector
== NULL
)
1185 return(STATUS_INSUFFICIENT_RESOURCES
);
1187 /* Read current boot sector into buffer */
1188 RtlInitUnicodeString(&Name
,
1191 InitializeObjectAttributes(&ObjectAttributes
,
1193 OBJ_CASE_INSENSITIVE
,
1197 Status
= NtOpenFile(&FileHandle
,
1202 FILE_SYNCHRONOUS_IO_NONALERT
);
1203 if (!NT_SUCCESS(Status
))
1205 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1209 Status
= NtReadFile(FileHandle
,
1218 NtClose(FileHandle
);
1219 if (!NT_SUCCESS(Status
))
1221 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1226 /* Allocate buffer for new bootsector */
1227 NewBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1230 if (NewBootSector
== NULL
)
1232 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1233 return(STATUS_INSUFFICIENT_RESOURCES
);
1236 /* Read new bootsector from SrcPath */
1237 RtlInitUnicodeString(&Name
,
1240 InitializeObjectAttributes(&ObjectAttributes
,
1242 OBJ_CASE_INSENSITIVE
,
1246 Status
= NtOpenFile(&FileHandle
,
1251 FILE_SYNCHRONOUS_IO_NONALERT
);
1252 if (!NT_SUCCESS(Status
))
1254 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1255 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1259 Status
= NtReadFile(FileHandle
,
1268 NtClose(FileHandle
);
1269 if (!NT_SUCCESS(Status
))
1271 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1272 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1276 /* Adjust bootsector (copy a part of the FAT16 BPB) */
1277 memcpy((NewBootSector
+ 3),
1278 (OrigBootSector
+ 3),
1279 59); /* FAT16 BPB length*/
1281 /* Free the original boot sector */
1282 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1284 /* Write new bootsector to RootPath */
1285 RtlInitUnicodeString(&Name
,
1288 InitializeObjectAttributes(&ObjectAttributes
,
1294 Status
= NtOpenFile(&FileHandle
,
1299 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
);
1300 if (!NT_SUCCESS(Status
))
1302 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1303 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1308 FilePosition
.QuadPart
= 0;
1310 Status
= NtWriteFile(FileHandle
,
1319 NtClose(FileHandle
);
1321 /* Free the new boot sector */
1322 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1329 InstallFat32BootCodeToDisk(PWSTR SrcPath
,
1332 OBJECT_ATTRIBUTES ObjectAttributes
;
1333 IO_STATUS_BLOCK IoStatusBlock
;
1334 UNICODE_STRING Name
;
1337 PUCHAR OrigBootSector
;
1338 PUCHAR NewBootSector
;
1339 LARGE_INTEGER FileOffset
;
1340 USHORT BackupBootSector
;
1342 /* Allocate buffer for original bootsector */
1343 OrigBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1346 if (OrigBootSector
== NULL
)
1347 return(STATUS_INSUFFICIENT_RESOURCES
);
1349 /* Read current boot sector into buffer */
1350 RtlInitUnicodeString(&Name
,
1353 InitializeObjectAttributes(&ObjectAttributes
,
1355 OBJ_CASE_INSENSITIVE
,
1359 Status
= NtOpenFile(&FileHandle
,
1364 FILE_SYNCHRONOUS_IO_NONALERT
);
1365 if (!NT_SUCCESS(Status
))
1367 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1371 Status
= NtReadFile(FileHandle
,
1380 NtClose(FileHandle
);
1381 if (!NT_SUCCESS(Status
))
1383 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1388 /* Allocate buffer for new bootsector (2 sectors) */
1389 NewBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1392 if (NewBootSector
== NULL
)
1394 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1395 return(STATUS_INSUFFICIENT_RESOURCES
);
1398 /* Read new bootsector from SrcPath */
1399 RtlInitUnicodeString(&Name
,
1402 InitializeObjectAttributes(&ObjectAttributes
,
1404 OBJ_CASE_INSENSITIVE
,
1408 Status
= NtOpenFile(&FileHandle
,
1413 FILE_SYNCHRONOUS_IO_NONALERT
);
1414 if (!NT_SUCCESS(Status
))
1416 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1417 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1421 Status
= NtReadFile(FileHandle
,
1430 NtClose(FileHandle
);
1431 if (!NT_SUCCESS(Status
))
1433 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1434 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1438 /* Adjust bootsector (copy a part of the FAT32 BPB) */
1439 memcpy((NewBootSector
+ 3),
1440 (OrigBootSector
+ 3),
1441 87); /* FAT32 BPB length */
1443 /* Get the location of the backup boot sector */
1444 BackupBootSector
= (OrigBootSector
[0x33] << 8) + OrigBootSector
[0x32];
1446 /* Free the original boot sector */
1447 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1449 /* Write the first sector of the new bootcode to DstPath */
1450 RtlInitUnicodeString(&Name
,
1453 InitializeObjectAttributes(&ObjectAttributes
,
1459 Status
= NtOpenFile(&FileHandle
,
1464 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
);
1465 if (!NT_SUCCESS(Status
))
1467 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1468 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1472 /* Write sector 0 */
1473 FileOffset
.QuadPart
= 0ULL;
1474 Status
= NtWriteFile(FileHandle
,
1483 if (!NT_SUCCESS(Status
))
1485 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status
);
1486 NtClose(FileHandle
);
1487 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1491 /* Write backup boot sector */
1492 if ((BackupBootSector
!= 0x0000) && (BackupBootSector
!= 0xFFFF))
1494 FileOffset
.QuadPart
= (ULONGLONG
)((ULONG
)BackupBootSector
* SECTORSIZE
);
1495 Status
= NtWriteFile(FileHandle
,
1504 if (!NT_SUCCESS(Status
))
1506 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status
);
1507 NtClose(FileHandle
);
1508 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1513 /* Write sector 14 */
1514 FileOffset
.QuadPart
= (ULONGLONG
)(14 * SECTORSIZE
);
1515 Status
= NtWriteFile(FileHandle
,
1520 (NewBootSector
+ SECTORSIZE
),
1524 if (!NT_SUCCESS(Status
))
1526 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status
);
1528 NtClose(FileHandle
);
1530 /* Free the new boot sector */
1531 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1538 UnprotectBootIni(PWSTR FileName
,
1541 UNICODE_STRING Name
;
1542 OBJECT_ATTRIBUTES ObjectAttributes
;
1543 IO_STATUS_BLOCK IoStatusBlock
;
1544 FILE_BASIC_INFORMATION FileInfo
;
1548 RtlInitUnicodeString(&Name
,
1551 InitializeObjectAttributes(&ObjectAttributes
,
1553 OBJ_CASE_INSENSITIVE
,
1557 Status
= NtOpenFile(&FileHandle
,
1558 GENERIC_READ
|GENERIC_WRITE
,
1562 FILE_SYNCHRONOUS_IO_NONALERT
);
1563 if (Status
== STATUS_NO_SUCH_FILE
)
1565 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1567 return(STATUS_SUCCESS
);
1569 if (!NT_SUCCESS(Status
))
1571 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1575 Status
= NtQueryInformationFile(FileHandle
,
1578 sizeof(FILE_BASIC_INFORMATION
),
1579 FileBasicInformation
);
1580 if (!NT_SUCCESS(Status
))
1582 DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status
);
1583 NtClose(FileHandle
);
1587 *Attributes
= FileInfo
.FileAttributes
;
1589 /* Delete attributes SYSTEM, HIDDEN and READONLY */
1590 FileInfo
.FileAttributes
= FileInfo
.FileAttributes
&
1591 ~(FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_READONLY
);
1593 Status
= NtSetInformationFile(FileHandle
,
1596 sizeof(FILE_BASIC_INFORMATION
),
1597 FileBasicInformation
);
1598 if (!NT_SUCCESS(Status
))
1600 DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status
);
1603 NtClose(FileHandle
);
1609 ProtectBootIni(PWSTR FileName
,
1612 UNICODE_STRING Name
;
1613 OBJECT_ATTRIBUTES ObjectAttributes
;
1614 IO_STATUS_BLOCK IoStatusBlock
;
1615 FILE_BASIC_INFORMATION FileInfo
;
1619 RtlInitUnicodeString(&Name
,
1622 InitializeObjectAttributes(&ObjectAttributes
,
1624 OBJ_CASE_INSENSITIVE
,
1628 Status
= NtOpenFile(&FileHandle
,
1629 GENERIC_READ
|GENERIC_WRITE
,
1633 FILE_SYNCHRONOUS_IO_NONALERT
);
1634 if (!NT_SUCCESS(Status
))
1636 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1640 Status
= NtQueryInformationFile(FileHandle
,
1643 sizeof(FILE_BASIC_INFORMATION
),
1644 FileBasicInformation
);
1645 if (!NT_SUCCESS(Status
))
1647 DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status
);
1648 NtClose(FileHandle
);
1652 FileInfo
.FileAttributes
= FileInfo
.FileAttributes
| Attributes
;
1654 Status
= NtSetInformationFile(FileHandle
,
1657 sizeof(FILE_BASIC_INFORMATION
),
1658 FileBasicInformation
);
1659 if (!NT_SUCCESS(Status
))
1661 DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status
);
1664 NtClose(FileHandle
);
1670 UpdateBootIni(PWSTR BootIniPath
,
1674 UNICODE_STRING Name
;
1675 PINICACHE Cache
= NULL
;
1676 PINICACHESECTION Section
= NULL
;
1678 ULONG FileAttribute
;
1680 RtlInitUnicodeString(&Name
,
1683 Status
= IniCacheLoad(&Cache
,
1686 if (!NT_SUCCESS(Status
))
1691 Section
= IniCacheGetSection(Cache
,
1692 L
"operating systems");
1693 if (Section
== NULL
)
1695 IniCacheDestroy(Cache
);
1696 return(STATUS_UNSUCCESSFUL
);
1699 IniCacheInsertKey(Section
,
1705 Status
= UnprotectBootIni(BootIniPath
,
1707 if (!NT_SUCCESS(Status
))
1709 IniCacheDestroy(Cache
);
1713 Status
= IniCacheSave(Cache
,
1715 if (!NT_SUCCESS(Status
))
1717 IniCacheDestroy(Cache
);
1721 FileAttribute
|= (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_READONLY
);
1722 Status
= ProtectBootIni(BootIniPath
,
1725 IniCacheDestroy(Cache
);
1732 CheckInstallFatBootcodeToPartition(PUNICODE_STRING SystemRootPath
)
1734 if (DoesFileExist(SystemRootPath
->Buffer
, L
"ntldr") ||
1735 DoesFileExist(SystemRootPath
->Buffer
, L
"boot.ini"))
1739 else if (DoesFileExist(SystemRootPath
->Buffer
, L
"io.sys") ||
1740 DoesFileExist(SystemRootPath
->Buffer
, L
"msdos.sys"))
1750 InstallFatBootcodeToPartition(PUNICODE_STRING SystemRootPath
,
1751 PUNICODE_STRING SourceRootPath
,
1752 PUNICODE_STRING DestinationArcPath
,
1753 UCHAR PartitionType
)
1755 WCHAR SrcPath
[MAX_PATH
];
1756 WCHAR DstPath
[MAX_PATH
];
1759 /* FAT or FAT32 partition */
1760 DPRINT1("System path: '%wZ'\n", SystemRootPath
);
1762 if (DoesFileExist(SystemRootPath
->Buffer
, L
"ntldr") == TRUE
||
1763 DoesFileExist(SystemRootPath
->Buffer
, L
"boot.ini") == TRUE
)
1765 /* Search root directory for 'ntldr' and 'boot.ini'. */
1766 DPRINT("Found Microsoft Windows NT/2000/XP boot loader\n");
1768 /* Copy FreeLoader to the boot partition */
1769 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1770 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
1771 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1772 wcscat(DstPath
, L
"\\freeldr.sys");
1774 DPRINT("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1775 Status
= SetupCopyFile(SrcPath
, DstPath
);
1776 if (!NT_SUCCESS(Status
))
1778 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
1782 /* Create or update freeldr.ini */
1783 if (DoesFileExist(SystemRootPath
->Buffer
, L
"freeldr.ini") == FALSE
)
1785 /* Create new 'freeldr.ini' */
1786 DPRINT1("Create new 'freeldr.ini'\n");
1787 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1788 wcscat(DstPath
, L
"\\freeldr.ini");
1790 Status
= CreateFreeLoaderIniForReactos(DstPath
,
1791 DestinationArcPath
->Buffer
);
1792 if (!NT_SUCCESS(Status
))
1794 DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status
);
1798 /* Install new bootcode */
1799 if (PartitionType
== PARTITION_FAT32
||
1800 PartitionType
== PARTITION_FAT32_XINT13
)
1802 /* Install FAT32 bootcode */
1803 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1804 wcscat(SrcPath
, L
"\\loader\\fat32.bin");
1805 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1806 wcscat(DstPath
, L
"\\bootsect.ros");
1808 DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath
, DstPath
);
1809 Status
= InstallFat32BootCodeToFile(SrcPath
,
1811 SystemRootPath
->Buffer
);
1812 if (!NT_SUCCESS(Status
))
1814 DPRINT1("InstallFat32BootCodeToFile() failed (Status %lx)\n", Status
);
1820 /* Install FAT16 bootcode */
1821 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1822 wcscat(SrcPath
, L
"\\loader\\fat.bin");
1823 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1824 wcscat(DstPath
, L
"\\bootsect.ros");
1826 DPRINT1("Install FAT bootcode: %S ==> %S\n", SrcPath
, DstPath
);
1827 Status
= InstallFat16BootCodeToFile(SrcPath
,
1829 SystemRootPath
->Buffer
);
1830 if (!NT_SUCCESS(Status
))
1832 DPRINT1("InstallFat16BootCodeToFile() failed (Status %lx)\n", Status
);
1837 /* Update 'boot.ini' */
1838 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1839 wcscat(DstPath
, L
"\\boot.ini");
1841 DPRINT1("Update 'boot.ini': %S\n", DstPath
);
1842 Status
= UpdateBootIni(DstPath
,
1843 L
"C:\\bootsect.ros",
1845 if (!NT_SUCCESS(Status
))
1847 DPRINT1("UpdateBootIni() failed (Status %lx)\n", Status
);
1853 /* Update existing 'freeldr.ini' */
1854 DPRINT1("Update existing 'freeldr.ini'\n");
1855 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1856 wcscat(DstPath
, L
"\\freeldr.ini");
1858 Status
= UpdateFreeLoaderIni(DstPath
,
1859 DestinationArcPath
->Buffer
);
1860 if (!NT_SUCCESS(Status
))
1862 DPRINT1("UpdateFreeLoaderIni() failed (Status %lx)\n", Status
);
1867 else if (DoesFileExist(SystemRootPath
->Buffer
, L
"io.sys") == TRUE
||
1868 DoesFileExist(SystemRootPath
->Buffer
, L
"msdos.sys") == TRUE
)
1870 /* Search for root directory for 'io.sys' and 'msdos.sys'. */
1871 DPRINT1("Found Microsoft DOS or Windows 9x boot loader\n");
1873 /* Copy FreeLoader to the boot partition */
1874 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1875 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
1876 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1877 wcscat(DstPath
, L
"\\freeldr.sys");
1879 DPRINT("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1880 Status
= SetupCopyFile(SrcPath
, DstPath
);
1881 if (!NT_SUCCESS(Status
))
1883 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
1887 /* Create or update 'freeldr.ini' */
1888 if (DoesFileExist(SystemRootPath
->Buffer
, L
"freeldr.ini") == FALSE
)
1890 /* Create new 'freeldr.ini' */
1891 DPRINT1("Create new 'freeldr.ini'\n");
1892 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1893 wcscat(DstPath
, L
"\\freeldr.ini");
1895 Status
= CreateFreeLoaderIniForDos(DstPath
,
1896 DestinationArcPath
->Buffer
);
1897 if (!NT_SUCCESS(Status
))
1899 DPRINT1("CreateFreeLoaderIniForDos() failed (Status %lx)\n", Status
);
1903 /* Save current bootsector as 'BOOTSECT.DOS' */
1904 wcscpy(SrcPath
, SystemRootPath
->Buffer
);
1905 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1906 wcscat(DstPath
, L
"\\bootsect.dos");
1908 DPRINT1("Save bootsector: %S ==> %S\n", SrcPath
, DstPath
);
1909 Status
= SaveCurrentBootSector(SrcPath
,
1911 if (!NT_SUCCESS(Status
))
1913 DPRINT1("SaveCurrentBootSector() failed (Status %lx)\n", Status
);
1917 /* Install new bootsector */
1918 if (PartitionType
== PARTITION_FAT32
||
1919 PartitionType
== PARTITION_FAT32_XINT13
)
1921 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1922 wcscat(SrcPath
, L
"\\loader\\fat32.bin");
1924 DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
1925 Status
= InstallFat32BootCodeToDisk(SrcPath
,
1926 SystemRootPath
->Buffer
);
1927 if (!NT_SUCCESS(Status
))
1929 DPRINT1("InstallFat32BootCodeToDisk() failed (Status %lx)\n", Status
);
1935 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1936 wcscat(SrcPath
, L
"\\loader\\fat.bin");
1938 DPRINT1("Install FAT bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
1939 Status
= InstallFat16BootCodeToDisk(SrcPath
,
1940 SystemRootPath
->Buffer
);
1941 if (!NT_SUCCESS(Status
))
1943 DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status
);
1950 /* Update existing 'freeldr.ini' */
1951 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1952 wcscat(DstPath
, L
"\\freeldr.ini");
1954 Status
= UpdateFreeLoaderIni(DstPath
,
1955 DestinationArcPath
->Buffer
);
1956 if (!NT_SUCCESS(Status
))
1958 DPRINT1("UpdateFreeLoaderIni() failed (Status %lx)\n", Status
);
1965 /* No or unknown boot loader */
1966 DPRINT1("No or unknown boot loader found\n");
1968 /* Copy FreeLoader to the boot partition */
1969 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1970 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
1971 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1972 wcscat(DstPath
, L
"\\freeldr.sys");
1974 DPRINT1("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1975 Status
= SetupCopyFile(SrcPath
, DstPath
);
1976 if (!NT_SUCCESS(Status
))
1978 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
1982 /* Create or update 'freeldr.ini' */
1983 if (DoesFileExist(SystemRootPath
->Buffer
, L
"freeldr.ini") == FALSE
)
1985 /* Create new freeldr.ini */
1986 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1987 wcscat(DstPath
, L
"\\freeldr.ini");
1989 DPRINT1("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1990 Status
= CreateFreeLoaderIniForReactos(DstPath
,
1991 DestinationArcPath
->Buffer
);
1992 if (!NT_SUCCESS(Status
))
1994 DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status
);
1998 /* Save current bootsector as 'BOOTSECT.OLD' */
1999 wcscpy(SrcPath
, SystemRootPath
->Buffer
);
2000 wcscpy(DstPath
, SystemRootPath
->Buffer
);
2001 wcscat(DstPath
, L
"\\bootsect.old");
2003 DPRINT1("Save bootsector: %S ==> %S\n", SrcPath
, DstPath
);
2004 Status
= SaveCurrentBootSector(SrcPath
,
2006 if (!NT_SUCCESS(Status
))
2008 DPRINT1("SaveCurrentBootSector() failed (Status %lx)\n", Status
);
2012 /* Install new bootsector */
2013 if (PartitionType
== PARTITION_FAT32
||
2014 PartitionType
== PARTITION_FAT32_XINT13
)
2016 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2017 wcscat(SrcPath
, L
"\\loader\\fat32.bin");
2019 DPRINT("Install FAT32 bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
2020 Status
= InstallFat32BootCodeToDisk(SrcPath
,
2021 SystemRootPath
->Buffer
);
2022 if (!NT_SUCCESS(Status
))
2024 DPRINT1("InstallFat32BootCodeToDisk() failed (Status %lx)\n", Status
);
2030 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2031 wcscat(SrcPath
, L
"\\loader\\fat.bin");
2033 DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
2034 Status
= InstallFat16BootCodeToDisk(SrcPath
,
2035 SystemRootPath
->Buffer
);
2036 if (!NT_SUCCESS(Status
))
2038 DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status
);
2045 /* Update existing 'freeldr.ini' */
2046 wcscpy(DstPath
, SystemRootPath
->Buffer
);
2047 wcscat(DstPath
, L
"\\freeldr.ini");
2049 Status
= UpdateFreeLoaderIni(DstPath
,
2050 DestinationArcPath
->Buffer
);
2051 if (!NT_SUCCESS(Status
))
2053 DPRINT1("UpdateFreeLoaderIni() failed (Status %lx)\n", Status
);
2059 return STATUS_SUCCESS
;
2064 InstallFatBootcodeToFloppy(PUNICODE_STRING SourceRootPath
,
2065 PUNICODE_STRING DestinationArcPath
)
2067 WCHAR SrcPath
[MAX_PATH
];
2068 WCHAR DstPath
[MAX_PATH
];
2071 /* Copy FreeLoader to the boot partition */
2072 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2073 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
2075 wcscpy(DstPath
, L
"\\Device\\Floppy0\\freeldr.sys");
2077 DPRINT("Copy: %S ==> %S\n", SrcPath
, DstPath
);
2078 Status
= SetupCopyFile(SrcPath
, DstPath
);
2079 if (!NT_SUCCESS(Status
))
2081 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
2085 /* Create new 'freeldr.ini' */
2086 wcscpy(DstPath
, L
"\\Device\\Floppy0\\freeldr.ini");
2088 DPRINT("Create new 'freeldr.ini'\n");
2089 Status
= CreateFreeLoaderIniForReactos(DstPath
,
2090 DestinationArcPath
->Buffer
);
2091 if (!NT_SUCCESS(Status
))
2093 DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status
);
2097 /* Install FAT12/16 boosector */
2098 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2099 wcscat(SrcPath
, L
"\\loader\\fat.bin");
2101 wcscpy(DstPath
, L
"\\Device\\Floppy0");
2103 DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath
, DstPath
);
2104 Status
= InstallFat16BootCodeToDisk(SrcPath
,
2106 if (!NT_SUCCESS(Status
))
2108 DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status
);
2112 return STATUS_SUCCESS
;