3 * Copyright (C) 1998-2003 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /* INCLUDES *******************************************************************/
26 /* FUNCTIONS ******************************************************************/
29 LoadAndBootBootSector(
38 /* Find all the message box settings and run them */
39 UiShowMessageBoxesInArgv(Argc
, Argv
);
41 /* Read the file name */
42 FileName
= GetArgumentValue(Argc
, Argv
, "BootSectorFile");
45 UiMessageBox("Boot sector file not specified for selected OS!");
49 FileId
= FsOpenFile(FileName
);
52 UiMessageBox("%s not found.", FileName
);
56 /* Read boot sector */
57 if ((ArcRead(FileId
, (PVOID
)0x7c00, 512, &BytesRead
) != ESUCCESS
) || (BytesRead
!= 512))
59 UiMessageBox("Unable to read boot sector.");
65 /* Check for validity */
66 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
68 UiMessageBox("Invalid boot sector magic (0xaa55)");
72 UiUnInitialize("Booting...");
76 * Don't stop the floppy drive motor when we
77 * are just booting a bootsector, or drive, or partition.
78 * If we were to stop the floppy motor then
79 * the BIOS wouldn't be informed and if the
80 * next read is to a floppy then the BIOS will
81 * still think the motor is on and this will
82 * result in a read error.
84 // DiskStopFloppyMotor();
85 /* NOTE: Don't touch FrldrBootDrive */
86 ChainLoadBiosBootSectorCode();
87 Reboot(); /* Must not return! */
92 LoadAndBootPartitionOrDrive(
94 IN ULONG PartitionNumber OPTIONAL
)
98 CHAR ArcPath
[MAX_PATH
];
100 /* Construct the corresponding ARC path */
101 ConstructArcPath(ArcPath
, "", DriveNumber
, PartitionNumber
);
102 *strrchr(ArcPath
, '\\') = ANSI_NULL
; // Trim the trailing path separator.
103 if (ArcOpen(ArcPath
, OpenReadOnly
, &FileId
) != ESUCCESS
)
105 UiMessageBox("Unable to open %s", ArcPath
);
110 * Now try to read the partition boot sector or the MBR (when PartitionNumber == 0).
111 * If this fails then abort.
113 if ((ArcRead(FileId
, (PVOID
)0x7c00, 512, &BytesRead
) != ESUCCESS
) || (BytesRead
!= 512))
115 if (PartitionNumber
!= 0)
116 UiMessageBox("Unable to read partition's boot sector.");
118 UiMessageBox("Unable to read MBR boot sector.");
124 /* Check for validity */
125 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
127 UiMessageBox("Invalid boot sector magic (0xaa55)");
131 UiUnInitialize("Booting...");
135 * Don't stop the floppy drive motor when we
136 * are just booting a bootsector, or drive, or partition.
137 * If we were to stop the floppy motor then
138 * the BIOS wouldn't be informed and if the
139 * next read is to a floppy then the BIOS will
140 * still think the motor is on and this will
141 * result in a read error.
143 // DiskStopFloppyMotor();
144 FrldrBootDrive
= DriveNumber
;
145 FrldrBootPartition
= PartitionNumber
;
146 ChainLoadBiosBootSectorCode();
147 Reboot(); /* Must not return! */
152 LoadAndBootPartition(
159 ULONG PartitionNumber
;
161 /* Find all the message box settings and run them */
162 UiShowMessageBoxesInArgv(Argc
, Argv
);
164 /* Read the boot drive */
165 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootDrive");
168 UiMessageBox("Boot drive not specified for selected OS!");
171 DriveNumber
= DriveMapGetBiosDriveNumber(ArgValue
);
173 /* Read the boot partition */
174 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootPartition");
177 UiMessageBox("Boot partition not specified for selected OS!");
180 PartitionNumber
= atoi(ArgValue
);
182 return LoadAndBootPartitionOrDrive(DriveNumber
, PartitionNumber
);
194 /* Find all the message box settings and run them */
195 UiShowMessageBoxesInArgv(Argc
, Argv
);
197 /* Read the boot drive */
198 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootDrive");
201 UiMessageBox("Boot drive not specified for selected OS!");
204 DriveNumber
= DriveMapGetBiosDriveNumber(ArgValue
);
206 return LoadAndBootPartitionOrDrive(DriveNumber
, 0);