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
= NtCreateFile(&FileHandle
,
1142 FILE_ATTRIBUTE_NORMAL
,
1145 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
,
1148 if (!NT_SUCCESS(Status
))
1150 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1154 Status
= NtWriteFile(FileHandle
,
1163 NtClose(FileHandle
);
1165 /* Free the new boot sector */
1166 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1173 InstallFat16BootCodeToDisk(PWSTR SrcPath
,
1176 OBJECT_ATTRIBUTES ObjectAttributes
;
1177 IO_STATUS_BLOCK IoStatusBlock
;
1178 UNICODE_STRING Name
;
1181 PUCHAR OrigBootSector
;
1182 PUCHAR NewBootSector
;
1184 /* Allocate buffer for original bootsector */
1185 OrigBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1188 if (OrigBootSector
== NULL
)
1189 return(STATUS_INSUFFICIENT_RESOURCES
);
1191 /* Read current boot sector into buffer */
1192 RtlInitUnicodeString(&Name
,
1195 InitializeObjectAttributes(&ObjectAttributes
,
1197 OBJ_CASE_INSENSITIVE
,
1201 Status
= NtOpenFile(&FileHandle
,
1206 FILE_SYNCHRONOUS_IO_NONALERT
);
1207 if (!NT_SUCCESS(Status
))
1209 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1213 Status
= NtReadFile(FileHandle
,
1222 NtClose(FileHandle
);
1223 if (!NT_SUCCESS(Status
))
1225 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1230 /* Allocate buffer for new bootsector */
1231 NewBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1234 if (NewBootSector
== NULL
)
1236 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1237 return(STATUS_INSUFFICIENT_RESOURCES
);
1240 /* Read new bootsector from SrcPath */
1241 RtlInitUnicodeString(&Name
,
1244 InitializeObjectAttributes(&ObjectAttributes
,
1246 OBJ_CASE_INSENSITIVE
,
1250 Status
= NtOpenFile(&FileHandle
,
1255 FILE_SYNCHRONOUS_IO_NONALERT
);
1256 if (!NT_SUCCESS(Status
))
1258 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1259 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1263 Status
= NtReadFile(FileHandle
,
1272 NtClose(FileHandle
);
1273 if (!NT_SUCCESS(Status
))
1275 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1276 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1280 /* Adjust bootsector (copy a part of the FAT16 BPB) */
1281 memcpy((NewBootSector
+ 3),
1282 (OrigBootSector
+ 3),
1283 59); /* FAT16 BPB length*/
1285 /* Free the original boot sector */
1286 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1288 /* Write new bootsector to RootPath */
1289 RtlInitUnicodeString(&Name
,
1292 InitializeObjectAttributes(&ObjectAttributes
,
1298 Status
= NtCreateFile(&FileHandle
,
1303 FILE_ATTRIBUTE_NORMAL
,
1306 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
,
1309 if (!NT_SUCCESS(Status
))
1311 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1316 FilePosition
.QuadPart
= 0;
1318 Status
= NtWriteFile(FileHandle
,
1327 NtClose(FileHandle
);
1329 /* Free the new boot sector */
1330 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1337 InstallFat32BootCodeToDisk(PWSTR SrcPath
,
1340 OBJECT_ATTRIBUTES ObjectAttributes
;
1341 IO_STATUS_BLOCK IoStatusBlock
;
1342 UNICODE_STRING Name
;
1345 PUCHAR OrigBootSector
;
1346 PUCHAR NewBootSector
;
1347 LARGE_INTEGER FileOffset
;
1348 USHORT BackupBootSector
;
1350 /* Allocate buffer for original bootsector */
1351 OrigBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1354 if (OrigBootSector
== NULL
)
1355 return(STATUS_INSUFFICIENT_RESOURCES
);
1357 /* Read current boot sector into buffer */
1358 RtlInitUnicodeString(&Name
,
1361 InitializeObjectAttributes(&ObjectAttributes
,
1363 OBJ_CASE_INSENSITIVE
,
1367 Status
= NtOpenFile(&FileHandle
,
1372 FILE_SYNCHRONOUS_IO_NONALERT
);
1373 if (!NT_SUCCESS(Status
))
1375 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1379 Status
= NtReadFile(FileHandle
,
1388 NtClose(FileHandle
);
1389 if (!NT_SUCCESS(Status
))
1391 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1396 /* Allocate buffer for new bootsector (2 sectors) */
1397 NewBootSector
= (PUCHAR
)RtlAllocateHeap(ProcessHeap
,
1400 if (NewBootSector
== NULL
)
1402 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1403 return(STATUS_INSUFFICIENT_RESOURCES
);
1406 /* Read new bootsector from SrcPath */
1407 RtlInitUnicodeString(&Name
,
1410 InitializeObjectAttributes(&ObjectAttributes
,
1412 OBJ_CASE_INSENSITIVE
,
1416 Status
= NtOpenFile(&FileHandle
,
1421 FILE_SYNCHRONOUS_IO_NONALERT
);
1422 if (!NT_SUCCESS(Status
))
1424 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1425 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1429 Status
= NtReadFile(FileHandle
,
1438 NtClose(FileHandle
);
1439 if (!NT_SUCCESS(Status
))
1441 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1442 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1446 /* Adjust bootsector (copy a part of the FAT32 BPB) */
1447 memcpy((NewBootSector
+ 3),
1448 (OrigBootSector
+ 3),
1449 87); /* FAT32 BPB length */
1451 /* Get the location of the backup boot sector */
1452 BackupBootSector
= (OrigBootSector
[0x33] << 8) + OrigBootSector
[0x32];
1454 /* Free the original boot sector */
1455 RtlFreeHeap(ProcessHeap
, 0, OrigBootSector
);
1457 /* Write the first sector of the new bootcode to DstPath */
1458 RtlInitUnicodeString(&Name
,
1461 InitializeObjectAttributes(&ObjectAttributes
,
1467 Status
= NtOpenFile(&FileHandle
,
1468 FILE_WRITE_ACCESS
| FILE_WRITE_ATTRIBUTES
,
1472 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_SEQUENTIAL_ONLY
);
1473 if (!NT_SUCCESS(Status
))
1475 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1476 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1480 /* Write sector 0 */
1481 FileOffset
.QuadPart
= 0ULL;
1482 Status
= NtWriteFile(FileHandle
,
1491 if (!NT_SUCCESS(Status
))
1493 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status
);
1494 NtClose(FileHandle
);
1495 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1499 /* Write backup boot sector */
1500 if ((BackupBootSector
!= 0x0000) && (BackupBootSector
!= 0xFFFF))
1502 FileOffset
.QuadPart
= (ULONGLONG
)((ULONG
)BackupBootSector
* SECTORSIZE
);
1503 Status
= NtWriteFile(FileHandle
,
1512 if (!NT_SUCCESS(Status
))
1514 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status
);
1515 NtClose(FileHandle
);
1516 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1521 /* Write sector 14 */
1522 FileOffset
.QuadPart
= (ULONGLONG
)(14 * SECTORSIZE
);
1523 Status
= NtWriteFile(FileHandle
,
1528 (NewBootSector
+ SECTORSIZE
),
1532 if (!NT_SUCCESS(Status
))
1534 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status
);
1536 NtClose(FileHandle
);
1538 /* Free the new boot sector */
1539 RtlFreeHeap(ProcessHeap
, 0, NewBootSector
);
1546 UnprotectBootIni(PWSTR FileName
,
1549 UNICODE_STRING Name
;
1550 OBJECT_ATTRIBUTES ObjectAttributes
;
1551 IO_STATUS_BLOCK IoStatusBlock
;
1552 FILE_BASIC_INFORMATION FileInfo
;
1556 RtlInitUnicodeString(&Name
,
1559 InitializeObjectAttributes(&ObjectAttributes
,
1561 OBJ_CASE_INSENSITIVE
,
1565 Status
= NtOpenFile(&FileHandle
,
1566 FILE_READ_ATTRIBUTES
| FILE_WRITE_ATTRIBUTES
,
1570 FILE_SYNCHRONOUS_IO_NONALERT
);
1571 if (Status
== STATUS_NO_SUCH_FILE
)
1573 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1575 return(STATUS_SUCCESS
);
1577 if (!NT_SUCCESS(Status
))
1579 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1583 Status
= NtQueryInformationFile(FileHandle
,
1586 sizeof(FILE_BASIC_INFORMATION
),
1587 FileBasicInformation
);
1588 if (!NT_SUCCESS(Status
))
1590 DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status
);
1591 NtClose(FileHandle
);
1595 *Attributes
= FileInfo
.FileAttributes
;
1597 /* Delete attributes SYSTEM, HIDDEN and READONLY */
1598 FileInfo
.FileAttributes
= FileInfo
.FileAttributes
&
1599 ~(FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_READONLY
);
1601 Status
= NtSetInformationFile(FileHandle
,
1604 sizeof(FILE_BASIC_INFORMATION
),
1605 FileBasicInformation
);
1606 if (!NT_SUCCESS(Status
))
1608 DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status
);
1611 NtClose(FileHandle
);
1617 ProtectBootIni(PWSTR FileName
,
1620 UNICODE_STRING Name
;
1621 OBJECT_ATTRIBUTES ObjectAttributes
;
1622 IO_STATUS_BLOCK IoStatusBlock
;
1623 FILE_BASIC_INFORMATION FileInfo
;
1627 RtlInitUnicodeString(&Name
,
1630 InitializeObjectAttributes(&ObjectAttributes
,
1632 OBJ_CASE_INSENSITIVE
,
1636 Status
= NtOpenFile(&FileHandle
,
1637 FILE_READ_ATTRIBUTES
| FILE_WRITE_ATTRIBUTES
,
1641 FILE_SYNCHRONOUS_IO_NONALERT
);
1642 if (!NT_SUCCESS(Status
))
1644 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
1648 Status
= NtQueryInformationFile(FileHandle
,
1651 sizeof(FILE_BASIC_INFORMATION
),
1652 FileBasicInformation
);
1653 if (!NT_SUCCESS(Status
))
1655 DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status
);
1656 NtClose(FileHandle
);
1660 FileInfo
.FileAttributes
= FileInfo
.FileAttributes
| Attributes
;
1662 Status
= NtSetInformationFile(FileHandle
,
1665 sizeof(FILE_BASIC_INFORMATION
),
1666 FileBasicInformation
);
1667 if (!NT_SUCCESS(Status
))
1669 DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status
);
1672 NtClose(FileHandle
);
1678 UpdateBootIni(PWSTR BootIniPath
,
1682 UNICODE_STRING Name
;
1683 PINICACHE Cache
= NULL
;
1684 PINICACHESECTION Section
= NULL
;
1686 ULONG FileAttribute
;
1688 RtlInitUnicodeString(&Name
,
1691 Status
= IniCacheLoad(&Cache
,
1694 if (!NT_SUCCESS(Status
))
1699 Section
= IniCacheGetSection(Cache
,
1700 L
"operating systems");
1701 if (Section
== NULL
)
1703 IniCacheDestroy(Cache
);
1704 return(STATUS_UNSUCCESSFUL
);
1707 IniCacheInsertKey(Section
,
1713 Status
= UnprotectBootIni(BootIniPath
,
1715 if (!NT_SUCCESS(Status
))
1717 IniCacheDestroy(Cache
);
1721 Status
= IniCacheSave(Cache
,
1723 if (!NT_SUCCESS(Status
))
1725 IniCacheDestroy(Cache
);
1729 FileAttribute
|= (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_READONLY
);
1730 Status
= ProtectBootIni(BootIniPath
,
1733 IniCacheDestroy(Cache
);
1740 CheckInstallFatBootcodeToPartition(PUNICODE_STRING SystemRootPath
)
1742 if (DoesFileExist(SystemRootPath
->Buffer
, L
"ntldr") ||
1743 DoesFileExist(SystemRootPath
->Buffer
, L
"boot.ini"))
1747 else if (DoesFileExist(SystemRootPath
->Buffer
, L
"io.sys") ||
1748 DoesFileExist(SystemRootPath
->Buffer
, L
"msdos.sys"))
1758 InstallFatBootcodeToPartition(PUNICODE_STRING SystemRootPath
,
1759 PUNICODE_STRING SourceRootPath
,
1760 PUNICODE_STRING DestinationArcPath
,
1761 UCHAR PartitionType
)
1763 WCHAR SrcPath
[MAX_PATH
];
1764 WCHAR DstPath
[MAX_PATH
];
1767 /* FAT or FAT32 partition */
1768 DPRINT1("System path: '%wZ'\n", SystemRootPath
);
1770 if (DoesFileExist(SystemRootPath
->Buffer
, L
"ntldr") == TRUE
||
1771 DoesFileExist(SystemRootPath
->Buffer
, L
"boot.ini") == TRUE
)
1773 /* Search root directory for 'ntldr' and 'boot.ini'. */
1774 DPRINT("Found Microsoft Windows NT/2000/XP boot loader\n");
1776 /* Copy FreeLoader to the boot partition */
1777 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1778 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
1779 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1780 wcscat(DstPath
, L
"\\freeldr.sys");
1782 DPRINT("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1783 Status
= SetupCopyFile(SrcPath
, DstPath
);
1784 if (!NT_SUCCESS(Status
))
1786 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
1790 /* Create or update freeldr.ini */
1791 if (DoesFileExist(SystemRootPath
->Buffer
, L
"freeldr.ini") == FALSE
)
1793 /* Create new 'freeldr.ini' */
1794 DPRINT1("Create new 'freeldr.ini'\n");
1795 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1796 wcscat(DstPath
, L
"\\freeldr.ini");
1798 Status
= CreateFreeLoaderIniForReactos(DstPath
,
1799 DestinationArcPath
->Buffer
);
1800 if (!NT_SUCCESS(Status
))
1802 DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status
);
1806 /* Install new bootcode */
1807 if (PartitionType
== PARTITION_FAT32
||
1808 PartitionType
== PARTITION_FAT32_XINT13
)
1810 /* Install FAT32 bootcode */
1811 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1812 wcscat(SrcPath
, L
"\\loader\\fat32.bin");
1813 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1814 wcscat(DstPath
, L
"\\bootsect.ros");
1816 DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath
, DstPath
);
1817 Status
= InstallFat32BootCodeToFile(SrcPath
,
1819 SystemRootPath
->Buffer
);
1820 if (!NT_SUCCESS(Status
))
1822 DPRINT1("InstallFat32BootCodeToFile() failed (Status %lx)\n", Status
);
1828 /* Install FAT16 bootcode */
1829 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1830 wcscat(SrcPath
, L
"\\loader\\fat.bin");
1831 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1832 wcscat(DstPath
, L
"\\bootsect.ros");
1834 DPRINT1("Install FAT bootcode: %S ==> %S\n", SrcPath
, DstPath
);
1835 Status
= InstallFat16BootCodeToFile(SrcPath
,
1837 SystemRootPath
->Buffer
);
1838 if (!NT_SUCCESS(Status
))
1840 DPRINT1("InstallFat16BootCodeToFile() failed (Status %lx)\n", Status
);
1845 /* Update 'boot.ini' */
1846 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1847 wcscat(DstPath
, L
"\\boot.ini");
1849 DPRINT1("Update 'boot.ini': %S\n", DstPath
);
1850 Status
= UpdateBootIni(DstPath
,
1851 L
"C:\\bootsect.ros",
1853 if (!NT_SUCCESS(Status
))
1855 DPRINT1("UpdateBootIni() failed (Status %lx)\n", Status
);
1861 /* Update existing 'freeldr.ini' */
1862 DPRINT1("Update existing 'freeldr.ini'\n");
1863 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1864 wcscat(DstPath
, L
"\\freeldr.ini");
1866 Status
= UpdateFreeLoaderIni(DstPath
,
1867 DestinationArcPath
->Buffer
);
1868 if (!NT_SUCCESS(Status
))
1870 DPRINT1("UpdateFreeLoaderIni() failed (Status %lx)\n", Status
);
1875 else if (DoesFileExist(SystemRootPath
->Buffer
, L
"io.sys") == TRUE
||
1876 DoesFileExist(SystemRootPath
->Buffer
, L
"msdos.sys") == TRUE
)
1878 /* Search for root directory for 'io.sys' and 'msdos.sys'. */
1879 DPRINT1("Found Microsoft DOS or Windows 9x boot loader\n");
1881 /* Copy FreeLoader to the boot partition */
1882 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1883 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
1884 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1885 wcscat(DstPath
, L
"\\freeldr.sys");
1887 DPRINT("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1888 Status
= SetupCopyFile(SrcPath
, DstPath
);
1889 if (!NT_SUCCESS(Status
))
1891 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
1895 /* Create or update 'freeldr.ini' */
1896 if (DoesFileExist(SystemRootPath
->Buffer
, L
"freeldr.ini") == FALSE
)
1898 /* Create new 'freeldr.ini' */
1899 DPRINT1("Create new 'freeldr.ini'\n");
1900 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1901 wcscat(DstPath
, L
"\\freeldr.ini");
1903 Status
= CreateFreeLoaderIniForDos(DstPath
,
1904 DestinationArcPath
->Buffer
);
1905 if (!NT_SUCCESS(Status
))
1907 DPRINT1("CreateFreeLoaderIniForDos() failed (Status %lx)\n", Status
);
1911 /* Save current bootsector as 'BOOTSECT.DOS' */
1912 wcscpy(SrcPath
, SystemRootPath
->Buffer
);
1913 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1914 wcscat(DstPath
, L
"\\bootsect.dos");
1916 DPRINT1("Save bootsector: %S ==> %S\n", SrcPath
, DstPath
);
1917 Status
= SaveCurrentBootSector(SrcPath
,
1919 if (!NT_SUCCESS(Status
))
1921 DPRINT1("SaveCurrentBootSector() failed (Status %lx)\n", Status
);
1925 /* Install new bootsector */
1926 if (PartitionType
== PARTITION_FAT32
||
1927 PartitionType
== PARTITION_FAT32_XINT13
)
1929 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1930 wcscat(SrcPath
, L
"\\loader\\fat32.bin");
1932 DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
1933 Status
= InstallFat32BootCodeToDisk(SrcPath
,
1934 SystemRootPath
->Buffer
);
1935 if (!NT_SUCCESS(Status
))
1937 DPRINT1("InstallFat32BootCodeToDisk() failed (Status %lx)\n", Status
);
1943 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1944 wcscat(SrcPath
, L
"\\loader\\fat.bin");
1946 DPRINT1("Install FAT bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
1947 Status
= InstallFat16BootCodeToDisk(SrcPath
,
1948 SystemRootPath
->Buffer
);
1949 if (!NT_SUCCESS(Status
))
1951 DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status
);
1958 /* Update existing 'freeldr.ini' */
1959 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1960 wcscat(DstPath
, L
"\\freeldr.ini");
1962 Status
= UpdateFreeLoaderIni(DstPath
,
1963 DestinationArcPath
->Buffer
);
1964 if (!NT_SUCCESS(Status
))
1966 DPRINT1("UpdateFreeLoaderIni() failed (Status %lx)\n", Status
);
1973 /* No or unknown boot loader */
1974 DPRINT1("No or unknown boot loader found\n");
1976 /* Copy FreeLoader to the boot partition */
1977 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
1978 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
1979 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1980 wcscat(DstPath
, L
"\\freeldr.sys");
1982 DPRINT1("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1983 Status
= SetupCopyFile(SrcPath
, DstPath
);
1984 if (!NT_SUCCESS(Status
))
1986 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
1990 /* Create or update 'freeldr.ini' */
1991 if (DoesFileExist(SystemRootPath
->Buffer
, L
"freeldr.ini") == FALSE
)
1993 /* Create new freeldr.ini */
1994 wcscpy(DstPath
, SystemRootPath
->Buffer
);
1995 wcscat(DstPath
, L
"\\freeldr.ini");
1997 DPRINT1("Copy: %S ==> %S\n", SrcPath
, DstPath
);
1998 Status
= CreateFreeLoaderIniForReactos(DstPath
,
1999 DestinationArcPath
->Buffer
);
2000 if (!NT_SUCCESS(Status
))
2002 DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status
);
2006 /* Save current bootsector as 'BOOTSECT.OLD' */
2007 wcscpy(SrcPath
, SystemRootPath
->Buffer
);
2008 wcscpy(DstPath
, SystemRootPath
->Buffer
);
2009 wcscat(DstPath
, L
"\\bootsect.old");
2011 DPRINT1("Save bootsector: %S ==> %S\n", SrcPath
, DstPath
);
2012 Status
= SaveCurrentBootSector(SrcPath
,
2014 if (!NT_SUCCESS(Status
))
2016 DPRINT1("SaveCurrentBootSector() failed (Status %lx)\n", Status
);
2020 /* Install new bootsector */
2021 if (PartitionType
== PARTITION_FAT32
||
2022 PartitionType
== PARTITION_FAT32_XINT13
)
2024 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2025 wcscat(SrcPath
, L
"\\loader\\fat32.bin");
2027 DPRINT("Install FAT32 bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
2028 Status
= InstallFat32BootCodeToDisk(SrcPath
,
2029 SystemRootPath
->Buffer
);
2030 if (!NT_SUCCESS(Status
))
2032 DPRINT1("InstallFat32BootCodeToDisk() failed (Status %lx)\n", Status
);
2038 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2039 wcscat(SrcPath
, L
"\\loader\\fat.bin");
2041 DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath
, SystemRootPath
->Buffer
);
2042 Status
= InstallFat16BootCodeToDisk(SrcPath
,
2043 SystemRootPath
->Buffer
);
2044 if (!NT_SUCCESS(Status
))
2046 DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status
);
2053 /* Update existing 'freeldr.ini' */
2054 wcscpy(DstPath
, SystemRootPath
->Buffer
);
2055 wcscat(DstPath
, L
"\\freeldr.ini");
2057 Status
= UpdateFreeLoaderIni(DstPath
,
2058 DestinationArcPath
->Buffer
);
2059 if (!NT_SUCCESS(Status
))
2061 DPRINT1("UpdateFreeLoaderIni() failed (Status %lx)\n", Status
);
2067 return STATUS_SUCCESS
;
2072 InstallFatBootcodeToFloppy(PUNICODE_STRING SourceRootPath
,
2073 PUNICODE_STRING DestinationArcPath
)
2075 WCHAR SrcPath
[MAX_PATH
];
2076 WCHAR DstPath
[MAX_PATH
];
2079 /* Copy FreeLoader to the boot partition */
2080 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2081 wcscat(SrcPath
, L
"\\loader\\freeldr.sys");
2083 wcscat(DstPath
, L
"\\Device\\Floppy0\\freeldr.sys");
2085 DPRINT("Copy: %S ==> %S\n", SrcPath
, DstPath
);
2086 Status
= SetupCopyFile(SrcPath
, DstPath
);
2087 if (!NT_SUCCESS(Status
))
2089 DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status
);
2093 /* Create new 'freeldr.ini' */
2094 wcscat(DstPath
, L
"\\Device\\Floppy0\\freeldr.ini");
2096 DPRINT("Create new 'freeldr.ini'\n");
2097 Status
= CreateFreeLoaderIniForReactos(DstPath
,
2098 DestinationArcPath
->Buffer
);
2099 if (!NT_SUCCESS(Status
))
2101 DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status
);
2105 /* Install FAT12/16 boosector */
2106 wcscpy(SrcPath
, SourceRootPath
->Buffer
);
2107 wcscat(SrcPath
, L
"\\loader\\fat.bin");
2109 wcscat(DstPath
, L
"\\Device\\Floppy0");
2111 DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath
, DstPath
);
2112 Status
= InstallFat16BootCodeToDisk(SrcPath
,
2114 if (!NT_SUCCESS(Status
))
2116 DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status
);
2120 return STATUS_SUCCESS
;