3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
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.
30 VOID
LoadAndBootBootSector(PUCHAR OperatingSystemName
)
33 UCHAR SettingName
[80];
34 UCHAR SettingValue
[80];
39 // Find all the message box settings and run them
40 ShowMessageBoxesInSection(OperatingSystemName
);
42 // Try to open the operating system section in the .ini file
43 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
45 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
46 MessageBox(SettingName
);
50 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
52 MessageBox("Boot drive not specified for selected OS!");
56 BootDrive
= atoi(SettingValue
);
59 if (IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, 80))
61 BootPartition
= atoi(SettingValue
);
64 if (!IniReadSettingByName(SectionId
, "BootSectorFile", FileName
, 260))
66 MessageBox("Boot sector file not specified for selected OS!");
70 if (!OpenDiskDrive(BootDrive
, BootPartition
))
72 MessageBox("Failed to open boot drive.");
76 FilePointer
= OpenFile(FileName
);
77 if (FilePointer
== NULL
)
79 strcat(FileName
, " not found.");
85 if (!ReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
87 DiskError("Disk read error.");
92 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
94 MessageBox("Invalid boot sector magic (0xaa55)");
104 VOID
LoadAndBootPartition(PUCHAR OperatingSystemName
)
106 UCHAR SettingName
[80];
107 UCHAR SettingValue
[80];
109 PARTITION_TABLE_ENTRY PartitionTableEntry
;
111 // Find all the message box settings and run them
112 ShowMessageBoxesInSection(OperatingSystemName
);
114 // Try to open the operating system section in the .ini file
115 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
117 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
118 MessageBox(SettingName
);
122 // Read the boot drive
123 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
125 MessageBox("Boot drive not specified for selected OS!");
129 BootDrive
= atoi(SettingValue
);
131 // Read the boot partition
132 if (!IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, 80))
134 MessageBox("Boot partition not specified for selected OS!");
138 BootPartition
= atoi(SettingValue
);
140 // Get the partition table entry
141 if (!DiskGetPartitionEntry(BootDrive
, BootPartition
, &PartitionTableEntry
))
146 // Now try to read the partition boot sector
147 // If this fails then abort
148 if (!DiskReadLogicalSectors(BootDrive
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
153 // Check for validity
154 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
156 MessageBox("Invalid boot sector magic (0xaa55)");
166 VOID
LoadAndBootDrive(PUCHAR OperatingSystemName
)
168 UCHAR SettingName
[80];
169 UCHAR SettingValue
[80];
172 // Find all the message box settings and run them
173 ShowMessageBoxesInSection(OperatingSystemName
);
175 // Try to open the operating system section in the .ini file
176 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
178 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
179 MessageBox(SettingName
);
183 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
185 MessageBox("Boot drive not specified for selected OS!");
189 BootDrive
= atoi(SettingValue
);
191 // Now try to read the boot sector (or mbr)
192 // If this fails then abort
193 if (!DiskReadLogicalSectors(BootDrive
, 0, 1, (PVOID
)0x7C00))
198 // Check for validity
199 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
201 MessageBox("Invalid boot sector magic (0xaa55)");