Re-apply 14698 - 14762 and fix resulting problem

svn path=/trunk/; revision=14819
This commit is contained in:
Gé van Geldorp 2005-04-26 18:18:36 +00:00
parent 9b91fad21c
commit b55b368e31
27 changed files with 564 additions and 315 deletions

View file

@ -47,10 +47,10 @@ EXTERN(RealEntryPoint)
.code32 .code32
/* Store the boot drive */ /* Store the boot drive */
movb %dl,(_BootDrive) movb %dl,(_i386BootDrive)
/* Store the boot partition */ /* Store the boot partition */
movb %dh,(_BootPartition) movb %dh,(_i386BootPartition)
/* GO! */ /* GO! */
xorl %eax,%eax xorl %eax,%eax
@ -275,9 +275,11 @@ EXTERN(_DisableA20)
* other boot loaders like Grub * other boot loaders like Grub
*/ */
#define MB_INFO_SIZE 90
#define MB_INFO_FLAGS_OFFSET 0 #define MB_INFO_FLAGS_OFFSET 0
#define MB_INFO_BOOT_DEVICE_OFFSET 12 #define MB_INFO_BOOT_DEVICE_OFFSET 12
#define MB_INFO_COMMAND_LINE_OFFSET 16 #define MB_INFO_COMMAND_LINE_OFFSET 16
#define CMDLINE_SIZE 256
/* /*
* We want to execute at 0x8000 (to be compatible with bootsector * We want to execute at 0x8000 (to be compatible with bootsector
@ -285,7 +287,6 @@ EXTERN(_DisableA20)
* above 1MB. So we let Grub load us there and then relocate * above 1MB. So we let Grub load us there and then relocate
* ourself to 0x8000 * ourself to 0x8000
*/ */
#define CMDLINE_BASE 0x7000
#define FREELDR_BASE 0x8000 #define FREELDR_BASE 0x8000
#define INITIAL_BASE 0x200000 #define INITIAL_BASE 0x200000
@ -328,6 +329,31 @@ mb1:
movw %dx,%ds movw %dx,%ds
movw %dx,%es movw %dx,%es
/* Check for valid multiboot signature */
cmpl $MULTIBOOT_BOOTLOADER_MAGIC,%eax
jne mbfail
/* Store multiboot info in a safe place */
movl %ebx,%esi
movl $(mb_info + INITIAL_BASE - FREELDR_BASE),%edi
movl $MB_INFO_SIZE,%ecx
rep movsb
/* Save commandline */
movl MB_INFO_FLAGS_OFFSET(%ebx),%edx
testl $MB_INFO_FLAG_COMMAND_LINE,MB_INFO_FLAGS_OFFSET(%ebx)
jz mb3
movl MB_INFO_COMMAND_LINE_OFFSET(%ebx),%esi
movl $(cmdline + INITIAL_BASE - FREELDR_BASE),%edi
movl $CMDLINE_SIZE,%ecx
mb2: lodsb
stosb
testb %al,%al
jz mb3
dec %ecx
jnz mb2
mb3:
/* Copy to low mem */ /* Copy to low mem */
movl $INITIAL_BASE,%esi movl $INITIAL_BASE,%esi
movl $FREELDR_BASE,%edi movl $FREELDR_BASE,%edi
@ -342,8 +368,8 @@ mb1:
/* Clear prefetch queue & correct CS, /* Clear prefetch queue & correct CS,
* jump to low mem */ * jump to low mem */
ljmp $PMODE_CS, $mb2 ljmp $PMODE_CS, $mb4
mb2: mb4:
/* Reload segment selectors */ /* Reload segment selectors */
movw $PMODE_DS,%dx movw $PMODE_DS,%dx
movw %dx,%ds movw %dx,%ds
@ -353,39 +379,28 @@ mb2:
movw %dx,%ss movw %dx,%ss
movl $STACK32ADDR,%esp movl $STACK32ADDR,%esp
/* Check for valid multiboot signature */ movl $mb_info,%ebx
cmpl $MULTIBOOT_BOOTLOADER_MAGIC,%eax
jne mbfail
/* See if the boot device was passed in */ /* See if the boot device was passed in */
movl MB_INFO_FLAGS_OFFSET(%ebx),%edx movl MB_INFO_FLAGS_OFFSET(%ebx),%edx
testl $MB_INFO_FLAG_BOOT_DEVICE,%edx testl $MB_INFO_FLAG_BOOT_DEVICE,%edx
jz mb3 jz mb5
/* Retrieve boot device info */ /* Retrieve boot device info */
movl MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax movl MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax
shrl $16,%eax shrl $16,%eax
incb %al incb %al
movb %al,_BootPartition movb %al,_i386BootPartition
movb %ah,_BootDrive movb %ah,_i386BootDrive
jmp mb4 jmp mb6
mb3: /* No boot device known, assume first partition of first harddisk */ mb5: /* No boot device known, assume first partition of first harddisk */
movb $0x80,_BootDrive movb $0x80,_i386BootDrive
movb $1,_BootPartition movb $1,_i386BootPartition
mb4:
/* Check for a command line */
xorl %eax,%eax
testl $MB_INFO_FLAG_COMMAND_LINE,%edx
jz mb6
/* Copy command line to low mem*/
movl MB_INFO_COMMAND_LINE_OFFSET(%ebx),%esi
movl $CMDLINE_BASE,%edi
mb5: lodsb
stosb
testb %al,%al
jnz mb5
movl $CMDLINE_BASE,%eax
mb6: mb6:
/* Check for command line */
mov $cmdline,%eax
testl $MB_INFO_FLAG_COMMAND_LINE,MB_INFO_FLAGS_OFFSET(%ebx)
jnz mb7
xorl %eax,%eax
mb7:
/* GO! */ /* GO! */
pushl %eax pushl %eax
@ -462,8 +477,14 @@ rmode_idtptr:
.word 0x3ff /* Limit */ .word 0x3ff /* Limit */
.long 0 /* Base Address */ .long 0 /* Base Address */
EXTERN(_BootDrive) EXTERN(_i386BootDrive)
.long 0 .long 0
EXTERN(_BootPartition) EXTERN(_i386BootPartition)
.long 0 .long 0
mb_info:
.fill MB_INFO_SIZE, 1, 0
cmdline:
.fill CMDLINE_SIZE, 1, 0

View file

@ -27,7 +27,7 @@
#include "rtl.h" #include "rtl.h"
VOID VOID
MachInit(VOID) MachInit(char *CmdLine)
{ {
ULONG PciId; ULONG PciId;
@ -39,11 +39,11 @@ MachInit(VOID)
PciId = READ_PORT_ULONG((ULONG*) 0xcfc); PciId = READ_PORT_ULONG((ULONG*) 0xcfc);
if (0x02a510de == PciId) if (0x02a510de == PciId)
{ {
XboxMachInit(); XboxMachInit(CmdLine);
} }
else else
{ {
PcMachInit(); PcMachInit(CmdLine);
} }
HalpCalibrateStallExecution(); HalpCalibrateStallExecution();

View file

@ -31,7 +31,7 @@ EXTERN(_ChainLoadBiosBootSectorCode)
.code16 .code16
/* Set the boot drive */ /* Set the boot drive */
movb (_BootDrive),%dl movb (_i386BootDrive),%dl
/* Load segment registers */ /* Load segment registers */
cli cli

View file

@ -0,0 +1,40 @@
/*
* FreeLoader
*
* Copyright (C) 2003 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __I386_I386_H_
#define __I386_I386_H_
extern ULONG i386BootDrive;
extern ULONG i386BootPartition;
extern BOOL i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector,
PULONGLONG SectorCount, int *FsType);
extern BOOL i386DiskGetSystemVolume(char *SystemPath, char *RemainingPath,
PULONG Device, PULONG DriveNumber,
PULONGLONG StartSector,
PULONGLONG SectorCount, int *FsType);
extern BOOL i386DiskGetBootPath(char *BootPath, unsigned Size);
extern VOID i386DiskGetBootDevice(PULONG BootDevice);
extern BOOL i386DiskBootingFromFloppy(VOID);
#endif /* __I386_I386_H_ */
/* EOF */

View file

@ -19,6 +19,8 @@
#include "freeldr.h" #include "freeldr.h"
#include "debug.h" #include "debug.h"
#include "i386.h"
#include "fsrec.h"
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS // FUNCTIONS
@ -166,4 +168,244 @@ BOOL DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT Buff
return TRUE; return TRUE;
} }
#endif // defined __i386__ BOOL i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
{
PARTITION_TABLE_ENTRY PartitionTableEntry;
UCHAR VolumeType;
DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", i386BootDrive, i386BootPartition));
// Check and see if it is a floppy drive
// If so then just assume FAT12 file system type
if (DiskIsDriveRemovable(i386BootDrive))
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
*DriveNumber = i386BootDrive;
*StartSector = 0;
*SectorCount = 2 * 80 * 18; /* FIXME hardcoded for 1.44 Mb */
*FsType = FS_FAT;
return TRUE;
}
// Check for ISO9660 file system type
if (i386BootDrive >= 0x80 && FsRecIsIso9660(i386BootDrive))
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
*DriveNumber = i386BootDrive;
*StartSector = 0;
*SectorCount = 0;
*FsType = FS_ISO9660;
return TRUE;
}
// Get the requested partition entry
if (i386BootPartition == 0)
{
// Partition requested was zero which means the boot partition
if (! DiskGetActivePartitionEntry(i386BootDrive, &PartitionTableEntry))
{
return FALSE;
}
}
else
{
// Get requested partition
if (! MachDiskGetPartitionEntry(i386BootDrive, i386BootPartition, &PartitionTableEntry))
{
return FALSE;
}
}
// Check for valid partition
if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
{
return FALSE;
}
// Try to recognize the file system
if (!FsRecognizeVolume(i386BootDrive, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
{
return FALSE;
}
*DriveNumber = i386BootDrive;
*StartSector = PartitionTableEntry.SectorCountBeforePartition;
*SectorCount = PartitionTableEntry.PartitionSectorCount;
//switch (PartitionTableEntry.SystemIndicator)
switch (VolumeType)
{
case PARTITION_FAT_12:
case PARTITION_FAT_16:
case PARTITION_HUGE:
case PARTITION_XINT13:
case PARTITION_FAT32:
case PARTITION_FAT32_XINT13:
*FsType = FS_FAT;
return TRUE;
case PARTITION_EXT2:
*FsType = FS_EXT2;
return TRUE;
case PARTITION_NTFS:
*FsType = FS_NTFS;
return TRUE;
default:
*FsType = 0;
return FALSE;
}
return TRUE;
}
VOID
i386DiskGetBootDevice(PULONG BootDevice)
{
((char *)BootDevice)[0] = (char)i386BootDrive;
((char *)BootDevice)[1] = (char)i386BootPartition;
}
BOOL
i386DiskBootingFromFloppy(VOID)
{
return i386BootDrive < 0x80;
}
#define IsRecognizedPartition(P) \
((P) == PARTITION_FAT_12 || \
(P) == PARTITION_FAT_16 || \
(P) == PARTITION_HUGE || \
(P) == PARTITION_IFS || \
(P) == PARTITION_EXT2 || \
(P) == PARTITION_FAT32 || \
(P) == PARTITION_FAT32_XINT13 || \
(P) == PARTITION_XINT13)
BOOL i386DiskGetSystemVolume(char *SystemPath,
char *RemainingPath,
PULONG Device,
PULONG DriveNumber,
PULONGLONG StartSector,
PULONGLONG SectorCount,
int *FsType)
{
ULONG PartitionNumber;
PARTITION_TABLE_ENTRY PartitionTableEntry;
UCHAR VolumeType;
CHAR BootPath[256];
unsigned i, RosPartition;
/*
* Verify system path
*/
if (!DissectArcPath(SystemPath, BootPath, DriveNumber, &PartitionNumber))
{
return FALSE;
}
if (NULL != RemainingPath)
{
strcpy(RemainingPath, BootPath);
}
/* 0xff -> no partition table present, use whole device */
if (0xff == PartitionNumber)
{
PartitionTableEntry.SectorCountBeforePartition = 0;
i = 0xff;
}
else
{
/* recalculate the boot partition for freeldr */
i = 0;
RosPartition = 0;
while (1)
{
if (!MachDiskGetPartitionEntry(*DriveNumber, ++i, &PartitionTableEntry))
{
return FALSE;
}
if (IsRecognizedPartition(PartitionTableEntry.SystemIndicator))
{
if (++RosPartition == PartitionNumber)
{
break;
}
}
}
}
/* Check for ISO9660 file system type */
if (*DriveNumber >= 0x80 && FsRecIsIso9660(*DriveNumber))
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
if (NULL != Device)
{
((char *)Device)[0] = (char)(*DriveNumber);
((char *)Device)[1] = (char)i;
}
*StartSector = 0;
*SectorCount = 0;
*FsType = FS_ISO9660;
return TRUE;
}
if (!FsRecognizeVolume(*DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
{
return FALSE;
}
if (NULL != Device)
{
((char *)Device)[0] = (char)(*DriveNumber);
((char *)Device)[1] = (char)i;
}
*StartSector = PartitionTableEntry.SectorCountBeforePartition;
*SectorCount = PartitionTableEntry.PartitionSectorCount;
switch (VolumeType)
{
case PARTITION_FAT_12:
case PARTITION_FAT_16:
case PARTITION_HUGE:
case PARTITION_XINT13:
case PARTITION_FAT32:
case PARTITION_FAT32_XINT13:
*FsType = FS_FAT;
return TRUE;
case PARTITION_EXT2:
*FsType = FS_EXT2;
return TRUE;
case PARTITION_NTFS:
*FsType = FS_NTFS;
return TRUE;
default:
*FsType = 0;
return FALSE;
}
return FALSE;
}
BOOL
i386DiskGetBootPath(char *BootPath, unsigned Size)
{
static char Path[] = "multi(0)disk(0)";
char Device[4];
itoa(i386BootDrive, Device, 10);
if (Size <= sizeof(Path) + 6 + strlen(Device))
{
return FALSE;
}
strcpy(BootPath, Path);
strcat(BootPath, MachDiskBootingFromFloppy() ? "fdisk" : "cdrom");
strcat(strcat(strcat(BootPath, "("), Device), ")");
return TRUE;
}
#endif /* defined __i386__ */
/* EOF */

View file

@ -30,7 +30,7 @@ EXTERN(_BootNewLinuxKernel)
.code16 .code16
/* Set the boot drive */ /* Set the boot drive */
movb (_BootDrive),%dl movb (_i386BootDrive),%dl
/* Load segment registers */ /* Load segment registers */
cli cli
@ -66,7 +66,7 @@ EXTERN(_BootOldLinuxKernel)
.code16 .code16
/* Set the boot drive */ /* Set the boot drive */
movb (_BootDrive),%dl movb (_i386BootDrive),%dl
/* Load segment registers */ /* Load segment registers */
cli cli

View file

@ -23,9 +23,10 @@
#include "machine.h" #include "machine.h"
#include "machpc.h" #include "machpc.h"
#include "rtl.h" #include "rtl.h"
#include "i386.h"
VOID VOID
PcMachInit(VOID) PcMachInit(char *CmdLine)
{ {
EnableA20(); EnableA20();
@ -48,6 +49,11 @@ PcMachInit(VOID)
MachVtbl.VideoSync = PcVideoSync; MachVtbl.VideoSync = PcVideoSync;
MachVtbl.VideoPrepareForReactOS = PcVideoPrepareForReactOS; MachVtbl.VideoPrepareForReactOS = PcVideoPrepareForReactOS;
MachVtbl.GetMemoryMap = PcMemGetMemoryMap; MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume;
MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume;
MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors; MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry; MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry;
MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry; MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;

View file

@ -26,7 +26,7 @@
#include "mm.h" #include "mm.h"
#endif #endif
VOID PcMachInit(VOID); VOID PcMachInit(char *CmdLine);
VOID PcConsPutChar(int Ch); VOID PcConsPutChar(int Ch);
BOOL PcConsKbHit(); BOOL PcConsKbHit();

View file

@ -21,9 +21,10 @@
#include "mm.h" #include "mm.h"
#include "machine.h" #include "machine.h"
#include "machxbox.h" #include "machxbox.h"
#include "i386.h"
VOID VOID
XboxMachInit(VOID) XboxMachInit(char *CmdLine)
{ {
/* Initialize our stuff */ /* Initialize our stuff */
XboxMemInit(); XboxMemInit();
@ -46,6 +47,11 @@ XboxMachInit(VOID)
MachVtbl.VideoSync = XboxVideoSync; MachVtbl.VideoSync = XboxVideoSync;
MachVtbl.VideoPrepareForReactOS = XboxVideoPrepareForReactOS; MachVtbl.VideoPrepareForReactOS = XboxVideoPrepareForReactOS;
MachVtbl.GetMemoryMap = XboxMemGetMemoryMap; MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume;
MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume;
MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors; MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry; MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry;
MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry; MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;

View file

@ -26,7 +26,7 @@
UCHAR XboxFont8x16[256 * 16]; UCHAR XboxFont8x16[256 * 16];
VOID XboxMachInit(VOID); VOID XboxMachInit(char *CmdLine);
VOID XboxConsPutChar(int Ch); VOID XboxConsPutChar(int Ch);
BOOL XboxConsKbHit(); BOOL XboxConsKbHit();

View file

@ -279,7 +279,7 @@ void PpcInit( of_proxy the_ofproxy ) {
BootMain("freeldr-ppc"); BootMain("freeldr-ppc");
} }
void MachInit() { void MachInit(char *CmdLine) {
int len; int len;
printf( "Determining boot device:\n" ); printf( "Determining boot device:\n" );
len = ofw_getprop(chosen_package, "bootpath", len = ofw_getprop(chosen_package, "bootpath",

View file

@ -49,6 +49,13 @@ VOID RunLoader(VOID)
LONG TimeOut; LONG TimeOut;
ULONG SelectedOperatingSystem; ULONG SelectedOperatingSystem;
if (!FsOpenBootVolume())
{
printf("Error opening boot partition for file access.\n");
MachConsGetCh();
return;
}
if (!IniFileInitialize()) if (!IniFileInitialize())
{ {
printf("Press any key to reboot.\n"); printf("Press any key to reboot.\n");

View file

@ -28,7 +28,8 @@
BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry) BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{ {
ULONG BootablePartitionCount = 0; ULONG BootablePartitionCount = 0;
ULONG ActivePartition = 0;
MASTER_BOOT_RECORD MasterBootRecord; MASTER_BOOT_RECORD MasterBootRecord;
// Read master boot record // Read master boot record
@ -41,22 +42,22 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY Parti
if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80) if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80)
{ {
BootablePartitionCount++; BootablePartitionCount++;
BootPartition = 0; ActivePartition = 0;
} }
if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80) if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80)
{ {
BootablePartitionCount++; BootablePartitionCount++;
BootPartition = 1; ActivePartition = 1;
} }
if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80) if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80)
{ {
BootablePartitionCount++; BootablePartitionCount++;
BootPartition = 2; ActivePartition = 2;
} }
if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80) if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80)
{ {
BootablePartitionCount++; BootablePartitionCount++;
BootPartition = 3; ActivePartition = 3;
} }
// Make sure there was only one bootable partition // Make sure there was only one bootable partition
@ -72,7 +73,7 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY Parti
} }
// Copy the partition table entry // Copy the partition table entry
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[BootPartition], sizeof(PARTITION_TABLE_ENTRY)); RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[ActivePartition], sizeof(PARTITION_TABLE_ENTRY));
return TRUE; return TRUE;
} }

View file

@ -31,7 +31,7 @@ VOID BootMain(char *CmdLine)
{ {
CmdLineParse(CmdLine); CmdLineParse(CmdLine);
MachInit(); MachInit(CmdLine);
DebugInit(); DebugInit();

View file

@ -51,110 +51,78 @@ VOID FileSystemError(PUCHAR ErrorString)
/* /*
* *
* BOOL FsOpenVolume(ULONG DriveNumber, ULONG PartitionNumber); * BOOL FsOpenVolume(ULONG DriveNumber, ULONGLONG StartSector, ULONGLONG SectorCount, int Type);
* *
* This function is called to open a disk volume for file access. * This function is called to open a disk volume for file access.
* It must be called before any of the file functions will work. * It must be called before any of the file functions will work.
* It takes two parameters:
*
* Drive: The BIOS drive number of the disk to open
* Partition: This is zero for floppy drives.
* If the disk is a hard disk then this specifies
* The partition number to open (1 - 4)
* If it is zero then it opens the active (bootable) partition
* *
*/ */
BOOL FsOpenVolume(ULONG DriveNumber, ULONG PartitionNumber) static BOOL FsOpenVolume(ULONG DriveNumber, ULONGLONG StartSector, ULONGLONG SectorCount, int Type)
{ {
PARTITION_TABLE_ENTRY PartitionTableEntry; UCHAR ErrorText[80];
UCHAR ErrorText[80];
UCHAR VolumeType;
DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", DriveNumber, PartitionNumber)); FsType = Type;
// Check and see if it is a floppy drive switch (FsType)
// If so then just assume FAT12 file system type
if (DiskIsDriveRemovable(DriveNumber))
{ {
DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n")); case FS_FAT:
return FatOpenVolume(DriveNumber, StartSector, SectorCount);
FsType = FS_FAT; case FS_EXT2:
return FatOpenVolume(DriveNumber, 0, 0); return Ext2OpenVolume(DriveNumber, StartSector);
} case FS_NTFS:
return NtfsOpenVolume(DriveNumber, StartSector);
// Check for ISO9660 file system type case FS_ISO9660:
if (DriveNumber >= 0x80 && FsRecIsIso9660(DriveNumber))
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
FsType = FS_ISO9660;
return IsoOpenVolume(DriveNumber); return IsoOpenVolume(DriveNumber);
}
// Set the boot partition
BootPartition = PartitionNumber;
// Get the requested partition entry
if (PartitionNumber == 0)
{
// Partition requested was zero which means the boot partition
if (DiskGetActivePartitionEntry(DriveNumber, &PartitionTableEntry) == FALSE)
{
FileSystemError("No active partition.");
return FALSE;
}
}
else
{
// Get requested partition
if (MachDiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry) == FALSE)
{
FileSystemError("Partition not found.");
return FALSE;
}
}
// Check for valid partition
if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
{
FileSystemError("Invalid partition.");
return FALSE;
}
// Try to recognize the file system
if (!FsRecognizeVolume(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
{
FileSystemError("Unrecognized file system.");
return FALSE;
}
//switch (PartitionTableEntry.SystemIndicator)
switch (VolumeType)
{
case PARTITION_FAT_12:
case PARTITION_FAT_16:
case PARTITION_HUGE:
case PARTITION_XINT13:
case PARTITION_FAT32:
case PARTITION_FAT32_XINT13:
FsType = FS_FAT;
return FatOpenVolume(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, PartitionTableEntry.PartitionSectorCount);
case PARTITION_EXT2:
FsType = FS_EXT2;
return Ext2OpenVolume(DriveNumber, PartitionTableEntry.SectorCountBeforePartition);
case PARTITION_NTFS:
FsType = FS_NTFS;
return NtfsOpenVolume(DriveNumber, PartitionTableEntry.SectorCountBeforePartition);
default: default:
FsType = 0; FsType = 0;
sprintf(ErrorText, "Unsupported file system. Type: 0x%x", VolumeType); sprintf(ErrorText, "Unsupported file system. Type: 0x%x", Type);
FileSystemError(ErrorText); FileSystemError(ErrorText);
}
return FALSE;
}
/*
*
* BOOL FsOpenBootVolume()
*
* This function is called to open the boot disk volume for file access.
* It must be called before any of the file functions will work.
*/
BOOL FsOpenBootVolume()
{
ULONG DriveNumber;
ULONGLONG StartSector;
ULONGLONG SectorCount;
int Type;
if (! MachDiskGetBootVolume(&DriveNumber, &StartSector, &SectorCount, &Type))
{
FileSystemError("Unable to locate boot partition\n");
return FALSE; return FALSE;
} }
return TRUE; return FsOpenVolume(DriveNumber, StartSector, SectorCount, Type);
} }
BOOL FsOpenSystemVolume(char *SystemPath, char *RemainingPath, PULONG Device)
{
ULONG DriveNumber;
ULONGLONG StartSector;
ULONGLONG SectorCount;
int Type;
if (! MachDiskGetSystemVolume(SystemPath, RemainingPath, Device,
&DriveNumber, &StartSector, &SectorCount,
&Type))
{
FileSystemError("Unable to locate system partition\n");
return FALSE;
}
return FsOpenVolume(DriveNumber, StartSector, SectorCount, Type);
}
PFILE FsOpenFile(PUCHAR FileName) PFILE FsOpenFile(PUCHAR FileName)
{ {
PFILE FileHandle = NULL; PFILE FileHandle = NULL;

View file

@ -38,8 +38,6 @@
#define ROUND_DOWN(N, S) ((N) & ~((S) - 1)) #define ROUND_DOWN(N, S) ((N) & ~((S) - 1))
#define Ke386EraseFlags(x) __asm__ __volatile__("pushl $0 ; popfl\n") #define Ke386EraseFlags(x) __asm__ __volatile__("pushl $0 ; popfl\n")
extern ULONG BootDrive; /* BIOS boot drive, 0-A:, 1-B:, 0x80-C:, 0x81-D:, etc. */
extern ULONG BootPartition; /* Boot Partition, 1-4 */
extern BOOL UserInterfaceUp; /* Tells us if the user interface is displayed */ extern BOOL UserInterfaceUp; /* Tells us if the user interface is displayed */
VOID BootMain(LPSTR CmdLine); VOID BootMain(LPSTR CmdLine);

View file

@ -33,7 +33,8 @@
#define PFILE FILE * #define PFILE FILE *
VOID FileSystemError(PUCHAR ErrorString); VOID FileSystemError(PUCHAR ErrorString);
BOOL FsOpenVolume(ULONG DriveNumber, ULONG PartitionNumber); BOOL FsOpenBootVolume();
BOOL FsOpenSystemVolume(char *SystemPath, char *RemainingPath, PULONG BootDevice);
PFILE FsOpenFile(PUCHAR FileName); PFILE FsOpenFile(PUCHAR FileName);
VOID FsCloseFile(PFILE FileHandle); VOID FsCloseFile(PFILE FileHandle);
BOOL FsReadFile(PFILE FileHandle, ULONG BytesToRead, ULONG* BytesRead, PVOID Buffer); BOOL FsReadFile(PFILE FileHandle, ULONG BytesToRead, ULONG* BytesRead, PVOID Buffer);

View file

@ -56,6 +56,11 @@ typedef struct tagMACHVTBL
ULONG (*GetMemoryMap)(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize); ULONG (*GetMemoryMap)(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize);
BOOL (*DiskGetBootVolume)(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType);
BOOL (*DiskGetSystemVolume)(char *SystemPath, char *RemainingPath, PULONG Device, PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType);
BOOL (*DiskGetBootPath)(char *BootPath, unsigned Size);
VOID (*DiskGetBootDevice)(PULONG BootDevice);
BOOL (*DiskBootingFromFloppy)(VOID);
BOOL (*DiskReadLogicalSectors)(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); BOOL (*DiskReadLogicalSectors)(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOL (*DiskGetPartitionEntry)(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOL (*DiskGetPartitionEntry)(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
BOOL (*DiskGetDriveGeometry)(ULONG DriveNumber, PGEOMETRY DriveGeometry); BOOL (*DiskGetDriveGeometry)(ULONG DriveNumber, PGEOMETRY DriveGeometry);
@ -66,7 +71,7 @@ typedef struct tagMACHVTBL
VOID (*HwDetect)(VOID); VOID (*HwDetect)(VOID);
} MACHVTBL, *PMACHVTBL; } MACHVTBL, *PMACHVTBL;
VOID MachInit(VOID); VOID MachInit(char *CmdLine);
extern MACHVTBL MachVtbl; extern MACHVTBL MachVtbl;
@ -87,6 +92,11 @@ extern MACHVTBL MachVtbl;
#define MachVideoSync() MachVtbl.VideoSync() #define MachVideoSync() MachVtbl.VideoSync()
#define MachVideoPrepareForReactOS() MachVtbl.VideoPrepareForReactOS() #define MachVideoPrepareForReactOS() MachVtbl.VideoPrepareForReactOS()
#define MachGetMemoryMap(MMap, Size) MachVtbl.GetMemoryMap((MMap), (Size)) #define MachGetMemoryMap(MMap, Size) MachVtbl.GetMemoryMap((MMap), (Size))
#define MachDiskGetBootVolume(Drv, Start, Cnt, FsType) MachVtbl.DiskGetBootVolume((Drv), (Start), (Cnt), (FsType))
#define MachDiskGetSystemVolume(SysPath, RemPath, Dev, Drv, Start, Cnt, FsType) MachVtbl.DiskGetSystemVolume((SysPath), (RemPath), (Dev), (Drv), (Start), (Cnt), (FsType))
#define MachDiskGetBootPath(Path, Size) MachVtbl.DiskGetBootPath((Path), (Size))
#define MachDiskGetBootDevice(BootDevice) MachVtbl.DiskGetBootDevice(BootDevice)
#define MachDiskBootingFromFloppy() MachVtbl.DiskBootingFromFloppy()
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf) MachVtbl.DiskReadLogicalSectors((Drive), (Start), (Count), (Buf)) #define MachDiskReadLogicalSectors(Drive, Start, Count, Buf) MachVtbl.DiskReadLogicalSectors((Drive), (Start), (Count), (Buf))
#define MachDiskGetPartitionEntry(Drive, Part, Entry) MachVtbl.DiskGetPartitionEntry((Drive), (Part), (Entry)) #define MachDiskGetPartitionEntry(Drive, Part, Entry) MachVtbl.DiskGetPartitionEntry((Drive), (Part), (Entry))
#define MachDiskGetDriveGeometry(Drive, Geom) MachVtbl.DiskGetDriveGeometry((Drive), (Geom)) #define MachDiskGetDriveGeometry(Drive, Geom) MachVtbl.DiskGetDriveGeometry((Drive), (Geom))

View file

@ -57,7 +57,7 @@ extern PINI_SECTION IniFileSectionListHead;
extern ULONG IniFileSectionCount; extern ULONG IniFileSectionCount;
extern ULONG IniFileSettingCount; extern ULONG IniFileSettingCount;
PFILE IniOpenIniFile(UCHAR BootDriveNumber, UCHAR BootPartitionNumber); PFILE IniOpenIniFile();
BOOL IniParseFile(PUCHAR IniFileData, ULONG IniFileSize); BOOL IniParseFile(PUCHAR IniFileData, ULONG IniFileSize);
ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset); ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset);

View file

@ -33,22 +33,7 @@ BOOL IniFileInitialize(VOID)
BOOL Success; BOOL Success;
// Open freeldr.ini // Open freeldr.ini
// BootDrive & BootPartition are passed Freeldr_Ini = IniOpenIniFile();
// in from the boot sector code in the
// DL & DH registers.
Freeldr_Ini = IniOpenIniFile(BootDrive, BootPartition);
// If we couldn't open freeldr.ini on the partition
// they specified in the boot sector then try
// opening the active (boot) partition.
if ((Freeldr_Ini == NULL) && (BootPartition != 0))
{
BootPartition = 0;
Freeldr_Ini = IniOpenIniFile(BootDrive, BootPartition);
return FALSE;
}
if (Freeldr_Ini == NULL) if (Freeldr_Ini == NULL)
{ {
@ -87,24 +72,10 @@ BOOL IniFileInitialize(VOID)
return Success; return Success;
} }
PFILE IniOpenIniFile(UCHAR BootDriveNumber, UCHAR BootPartitionNumber) PFILE IniOpenIniFile()
{ {
PFILE IniFileHandle; // File handle for freeldr.ini PFILE IniFileHandle; // File handle for freeldr.ini
if (!FsOpenVolume(BootDriveNumber, BootPartitionNumber))
{
if (BootPartitionNumber == 0)
{
printf("Error opening active (bootable) partition on boot drive 0x%x for file access.\n", BootDriveNumber);
}
else
{
printf("Error opening partition %d on boot drive 0x%x for file access.\n", BootPartitionNumber, BootDriveNumber);
}
return NULL;
}
// Try to open freeldr.ini // Try to open freeldr.ini
IniFileHandle = FsOpenFile("freeldr.ini"); IniFileHandle = FsOpenFile("freeldr.ini");

View file

@ -40,18 +40,19 @@
PLINUX_BOOTSECTOR LinuxBootSector = NULL; PLINUX_BOOTSECTOR LinuxBootSector = NULL;
PLINUX_SETUPSECTOR LinuxSetupSector = NULL; PLINUX_SETUPSECTOR LinuxSetupSector = NULL;
ULONG SetupSectorSize = 0; ULONG SetupSectorSize = 0;
BOOL NewStyleLinuxKernel = FALSE; BOOL NewStyleLinuxKernel = FALSE;
ULONG LinuxKernelSize = 0; ULONG LinuxKernelSize = 0;
ULONG LinuxInitrdSize = 0; ULONG LinuxInitrdSize = 0;
UCHAR LinuxKernelName[260]; UCHAR LinuxKernelName[260];
UCHAR LinuxInitrdName[260]; UCHAR LinuxInitrdName[260];
BOOL LinuxHasInitrd = FALSE; BOOL LinuxHasInitrd = FALSE;
UCHAR LinuxCommandLine[260] = ""; UCHAR LinuxCommandLine[260] = "";
ULONG LinuxCommandLineSize = 0; ULONG LinuxCommandLineSize = 0;
PVOID LinuxKernelLoadAddress = NULL; PVOID LinuxKernelLoadAddress = NULL;
PVOID LinuxInitrdLoadAddress = NULL; PVOID LinuxInitrdLoadAddress = NULL;
UCHAR LinuxBootDescription[80]; UCHAR LinuxBootDescription[80];
UCHAR LinuxBootPath[260] = "";
VOID LoadAndBootLinux(PUCHAR OperatingSystemName, PUCHAR Description) VOID LoadAndBootLinux(PUCHAR OperatingSystemName, PUCHAR Description)
{ {
@ -80,7 +81,7 @@ VOID LoadAndBootLinux(PUCHAR OperatingSystemName, PUCHAR Description)
} }
// Open the boot volume // Open the boot volume
if (!FsOpenVolume(BootDrive, BootPartition)) if (!FsOpenSystemVolume(LinuxBootPath, NULL, NULL))
{ {
UiMessageBox("Failed to open boot drive."); UiMessageBox("Failed to open boot drive.");
goto LinuxBootFailed; goto LinuxBootFailed;
@ -226,8 +227,7 @@ LinuxBootFailed:
BOOL LinuxParseIniSection(PUCHAR OperatingSystemName) BOOL LinuxParseIniSection(PUCHAR OperatingSystemName)
{ {
UCHAR SettingName[260]; UCHAR SettingName[260];
UCHAR SettingValue[260]; ULONG SectionId;
ULONG SectionId;
// Find all the message box settings and run them // Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName); UiShowMessageBoxesInSection(OperatingSystemName);
@ -240,20 +240,12 @@ BOOL LinuxParseIniSection(PUCHAR OperatingSystemName)
return FALSE; return FALSE;
} }
if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 260)) if (!IniReadSettingByName(SectionId, "BootPath", LinuxBootPath, 260))
{ {
UiMessageBox("Boot drive not specified for selected OS!"); UiMessageBox("Boot path not specified for selected OS!");
return FALSE; return FALSE;
} }
BootDrive = DriveMapGetBiosDriveNumber(SettingValue);
BootPartition = 0;
if (IniReadSettingByName(SectionId, "BootPartition", SettingValue, 260))
{
BootPartition = atoi(SettingValue);
}
// Get the kernel name // Get the kernel name
if (!IniReadSettingByName(SectionId, "Kernel", LinuxKernelName, 260)) if (!IniReadSettingByName(SectionId, "Kernel", LinuxKernelName, 260))
{ {

View file

@ -37,6 +37,11 @@
#undef MachVideoSync #undef MachVideoSync
#undef MachVideoPrepareForReactOS #undef MachVideoPrepareForReactOS
#undef MachGetMemoryMap #undef MachGetMemoryMap
#undef MachDiskGetBootVolume
#undef MachDiskGetSystemVolume
#undef MachDiskGetBootPath
#undef MachDiskGetBootDevice
#undef MachDiskBootingFromFloppy
#undef MachDiskReadLogicalSectors #undef MachDiskReadLogicalSectors
#undef MachDiskGetPartitionEntry #undef MachDiskGetPartitionEntry
#undef MachDiskGetDriveGeometry #undef MachDiskGetDriveGeometry
@ -148,6 +153,44 @@ MachGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize)
return MachVtbl.GetMemoryMap(BiosMemoryMap, MaxMemoryMapSize); return MachVtbl.GetMemoryMap(BiosMemoryMap, MaxMemoryMapSize);
} }
BOOL
MachDiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
{
return MachVtbl.DiskGetBootVolume(DriveNumber, StartSector, SectorCount, FsType);
}
BOOL
MachDiskGetSystemVolume(char *SystemPath,
char *RemainingPath,
PULONG Device,
PULONG DriveNumber,
PULONGLONG StartSector,
PULONGLONG SectorCount,
int *FsType)
{
return MachVtbl.DiskGetSystemVolume(SystemPath, RemainingPath, Device,
DriveNumber, StartSector, SectorCount,
FsType);
}
BOOL
MachDiskGetBootPath(char *BootPath, unsigned Size)
{
return MachVtbl.DiskGetBootPath(BootPath, Size);
}
VOID
MachDiskGetBootDevice(PULONG BootDevice)
{
MachVtbl.DiskGetBootDevice(BootDevice);
}
BOOL
MachDiskBootingFromFloppy()
{
return MachVtbl.DiskBootingFromFloppy();
}
BOOL BOOL
MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer) MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
{ {

View file

@ -33,10 +33,9 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
{ {
PFILE FilePointer; PFILE FilePointer;
UCHAR SettingName[80]; UCHAR SettingName[80];
UCHAR SettingValue[80]; ULONG SectionId;
ULONG SectionId;
UCHAR FileName[260]; UCHAR FileName[260];
ULONG BytesRead; ULONG BytesRead;
// Find all the message box settings and run them // Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName); UiShowMessageBoxesInSection(OperatingSystemName);
@ -49,27 +48,13 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
return; return;
} }
if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 80))
{
UiMessageBox("Boot drive not specified for selected OS!");
return;
}
BootDrive = DriveMapGetBiosDriveNumber(SettingValue);
BootPartition = 0;
if (IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80))
{
BootPartition = atoi(SettingValue);
}
if (!IniReadSettingByName(SectionId, "BootSectorFile", FileName, 260)) if (!IniReadSettingByName(SectionId, "BootSectorFile", FileName, 260))
{ {
UiMessageBox("Boot sector file not specified for selected OS!"); UiMessageBox("Boot sector file not specified for selected OS!");
return; return;
} }
if (!FsOpenVolume(BootDrive, BootPartition)) if (!FsOpenSystemVolume(FileName, FileName, NULL))
{ {
UiMessageBox("Failed to open boot drive."); UiMessageBox("Failed to open boot drive.");
return; return;
@ -111,10 +96,12 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
VOID LoadAndBootPartition(PUCHAR OperatingSystemName) VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
{ {
UCHAR SettingName[80]; UCHAR SettingName[80];
UCHAR SettingValue[80]; UCHAR SettingValue[80];
ULONG SectionId; ULONG SectionId;
PARTITION_TABLE_ENTRY PartitionTableEntry; PARTITION_TABLE_ENTRY PartitionTableEntry;
ULONG DriveNumber;
ULONG PartitionNumber;
// Find all the message box settings and run them // Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName); UiShowMessageBoxesInSection(OperatingSystemName);
@ -134,7 +121,7 @@ VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
return; return;
} }
BootDrive = DriveMapGetBiosDriveNumber(SettingValue); DriveNumber = DriveMapGetBiosDriveNumber(SettingValue);
// Read the boot partition // Read the boot partition
if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80)) if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80))
@ -143,17 +130,17 @@ VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
return; return;
} }
BootPartition = atoi(SettingValue); PartitionNumber = atoi(SettingValue);
// Get the partition table entry // Get the partition table entry
if (!DiskGetPartitionEntry(BootDrive, BootPartition, &PartitionTableEntry)) if (!DiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry))
{ {
return; return;
} }
// Now try to read the partition boot sector // Now try to read the partition boot sector
// If this fails then abort // If this fails then abort
if (!MachDiskReadLogicalSectors(BootDrive, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00)) if (!MachDiskReadLogicalSectors(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00))
{ {
return; return;
} }
@ -182,7 +169,8 @@ VOID LoadAndBootDrive(PUCHAR OperatingSystemName)
{ {
UCHAR SettingName[80]; UCHAR SettingName[80];
UCHAR SettingValue[80]; UCHAR SettingValue[80];
ULONG SectionId; ULONG SectionId;
ULONG DriveNumber;
// Find all the message box settings and run them // Find all the message box settings and run them
UiShowMessageBoxesInSection(OperatingSystemName); UiShowMessageBoxesInSection(OperatingSystemName);
@ -201,11 +189,11 @@ VOID LoadAndBootDrive(PUCHAR OperatingSystemName)
return; return;
} }
BootDrive = DriveMapGetBiosDriveNumber(SettingValue); DriveNumber = DriveMapGetBiosDriveNumber(SettingValue);
// Now try to read the boot sector (or mbr) // Now try to read the boot sector (or mbr)
// If this fails then abort // If this fails then abort
if (!MachDiskReadLogicalSectors(BootDrive, 0, 1, (PVOID)0x7C00)) if (!MachDiskReadLogicalSectors(DriveNumber, 0, 1, (PVOID)0x7C00))
{ {
return; return;
} }

View file

@ -43,7 +43,21 @@ BOOL DissectArcPath(char *ArcPath, char *BootPath, ULONG* BootDrive, ULONG* Boot
if (p == NULL) if (p == NULL)
return FALSE; return FALSE;
p++; p++;
*BootPartition = 0; *BootPartition = 0xff;
}
else if (strnicmp(p, "cdrom(", 6) == 0)
{
/*
* cdrom path:
* multi(0)disk(0)cdrom(x)\path
*/
p = p + 6;
*BootDrive = atoi(p);
p = strchr(p, ')');
if (p == NULL)
return FALSE;
p++;
*BootPartition = 0xff;
} }
else if (strnicmp(p, "rdisk(", 6) == 0) else if (strnicmp(p, "rdisk(", 6) == 0)
{ {

View file

@ -15,16 +15,6 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
#define IsRecognizedPartition(P) \
((P) == PARTITION_FAT_12 || \
(P) == PARTITION_FAT_16 || \
(P) == PARTITION_HUGE || \
(P) == PARTITION_IFS || \
(P) == PARTITION_EXT2 || \
(P) == PARTITION_FAT32 || \
(P) == PARTITION_FAT32_XINT13 || \
(P) == PARTITION_XINT13)
BOOL BOOL
STDCALL STDCALL
FrLdrLoadKernel(PCHAR szFileName, FrLdrLoadKernel(PCHAR szFileName,
@ -564,6 +554,7 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
PFILE FilePointer; PFILE FilePointer;
CHAR name[1024]; CHAR name[1024];
CHAR value[1024]; CHAR value[1024];
CHAR SystemPath[1024];
CHAR szKernelName[1024]; CHAR szKernelName[1024];
CHAR szHalName[1024]; CHAR szHalName[1024];
CHAR szFileName[1024]; CHAR szFileName[1024];
@ -574,9 +565,6 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
ULONG_PTR Base; ULONG_PTR Base;
ULONG Size; ULONG Size;
PARTITION_TABLE_ENTRY PartitionTableEntry;
ULONG rosPartition;
extern ULONG PageDirectoryStart; extern ULONG PageDirectoryStart;
extern ULONG PageDirectoryEnd; extern ULONG PageDirectoryEnd;
@ -645,7 +633,7 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
/* /*
* Make sure the system path is set in the .ini file * Make sure the system path is set in the .ini file
*/ */
if (!IniReadSettingByName(SectionId, "SystemPath", value, 1024)) if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath)))
{ {
UiMessageBox("System path not specified for selected operating system."); UiMessageBox("System path not specified for selected operating system.");
return; return;
@ -654,62 +642,20 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
/* /*
* Special case for Live CD. * Special case for Live CD.
*/ */
if (!stricmp(value, "LiveCD")) if (!stricmp(SystemPath, "LiveCD"))
{ {
strcpy(szBootPath, "\\reactos"); /* Normalize */
MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
/* Set kernel command line */ strcat(SystemPath, "\\reactos");
sprintf(multiboot_kernel_cmdline, strcat(strcpy(multiboot_kernel_cmdline, SystemPath),
"multi(0)disk(0)cdrom(%u)\\reactos /MININT", " /MININT");
(unsigned int)BootDrive);
} }
else else
{ {
/* /* copy system path into kernel command line */
* Verify system path strcpy(multiboot_kernel_cmdline, SystemPath);
*/
if (!DissectArcPath(value, szBootPath, &BootDrive, &BootPartition))
{
sprintf(MsgBuffer,"Invalid system path: '%s'", value);
UiMessageBox(MsgBuffer);
return;
}
/* recalculate the boot partition for freeldr */
i = 0;
rosPartition = 0;
while (1)
{
if (!MachDiskGetPartitionEntry(BootDrive, ++i, &PartitionTableEntry))
{
BootPartition = 0;
break;
}
if (IsRecognizedPartition(PartitionTableEntry.SystemIndicator))
{
if (++rosPartition == BootPartition)
{
BootPartition = i;
break;
}
}
}
if (BootPartition == 0)
{
sprintf(MsgBuffer,"Invalid system path: '%s'", value);
UiMessageBox(MsgBuffer);
return;
}
/* copy ARC path into kernel command line */
strcpy(multiboot_kernel_cmdline, value);
} }
/* Set boot drive and partition */
((LPSTR )(&LoaderBlock.BootDevice))[0] = (CHAR)BootDrive;
((LPSTR )(&LoaderBlock.BootDevice))[1] = (CHAR)BootPartition;
/* /*
* Read the optional kernel parameters (if any) * Read the optional kernel parameters (if any)
*/ */
@ -719,13 +665,6 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
strcat(multiboot_kernel_cmdline, value); strcat(multiboot_kernel_cmdline, value);
} }
/* append a backslash */
if ((strlen(szBootPath)==0) ||
szBootPath[strlen(szBootPath)] != '\\')
strcat(szBootPath, "\\");
DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
UiDrawBackdrop(); UiDrawBackdrop();
UiDrawStatusText("Detecting Hardware..."); UiDrawStatusText("Detecting Hardware...");
@ -741,14 +680,21 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
UiDrawProgressBarCenter(0, 100, "Loading ReactOS..."); UiDrawProgressBarCenter(0, 100, "Loading ReactOS...");
/* /*
* Try to open boot drive * Try to open system drive
*/ */
if (!FsOpenVolume(BootDrive, BootPartition)) if (!FsOpenSystemVolume(SystemPath, szBootPath, &LoaderBlock.BootDevice))
{ {
UiMessageBox("Failed to open boot drive."); UiMessageBox("Failed to open boot drive.");
return; return;
} }
/* append a backslash */
if ((strlen(szBootPath)==0) ||
szBootPath[strlen(szBootPath)] != '\\')
strcat(szBootPath, "\\");
DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
/* /*
* Find the kernel image name * Find the kernel image name
* and try to load the kernel off the disk * and try to load the kernel off the disk

View file

@ -312,13 +312,11 @@ VOID RunLoader(VOID)
UiDrawStatusText(""); UiDrawStatusText("");
#endif #endif
/* set boot drive and partition */ /* set boot device */
((char *)(&LoaderBlock.BootDevice))[0] = (char)BootDrive; MachDiskGetBootDevice(&LoaderBlock.BootDevice);
((char *)(&LoaderBlock.BootDevice))[1] = (char)BootPartition;
/* Open boot drive */ /* Open boot drive */
if (!FsOpenVolume(BootDrive, BootPartition)) if (!FsOpenBootVolume())
{ {
#ifdef USE_UI #ifdef USE_UI
UiMessageBox("Failed to open boot drive."); UiMessageBox("Failed to open boot drive.");
@ -330,7 +328,7 @@ VOID RunLoader(VOID)
/* Open 'txtsetup.sif' */ /* Open 'txtsetup.sif' */
if (!InfOpenFile (&InfHandle, if (!InfOpenFile (&InfHandle,
(BootDrive < 0x80) ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif", MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
&ErrorLine)) &ErrorLine))
{ {
printf("Failed to open 'txtsetup.sif'\n"); printf("Failed to open 'txtsetup.sif'\n");
@ -358,7 +356,7 @@ VOID RunLoader(VOID)
printf("LoadOptions: '%s'\n", LoadOptions); printf("LoadOptions: '%s'\n", LoadOptions);
#endif #endif
if (BootDrive < 0x80) if (MachDiskBootingFromFloppy())
{ {
/* Boot from floppy disk */ /* Boot from floppy disk */
SourcePath = "\\"; SourcePath = "\\";
@ -370,12 +368,9 @@ VOID RunLoader(VOID)
} }
/* Set kernel command line */ /* Set kernel command line */
sprintf(multiboot_kernel_cmdline, MachDiskGetBootPath(multiboot_kernel_cmdline, sizeof(multiboot_kernel_cmdline));
"multi(0)disk(0)%s(%u)%s %s", strcat(strcat(strcat(multiboot_kernel_cmdline, SourcePath), " "),
(BootDrive < 0x80) ? "fdisk" : "cdrom", LoadOptions);
(unsigned int)BootDrive,
SourcePath,
LoadOptions);
/* Load ntoskrnl.exe */ /* Load ntoskrnl.exe */
if (!LoadKernel(SourcePath, "ntoskrnl.exe")) if (!LoadKernel(SourcePath, "ntoskrnl.exe"))
@ -400,7 +395,7 @@ for(;;);
#endif #endif
/* Insert boot disk 2 */ /* Insert boot disk 2 */
if (BootDrive < 0x80) if (MachDiskBootingFromFloppy())
{ {
#ifdef USE_UI #ifdef USE_UI
UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER"); UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
@ -410,7 +405,7 @@ for(;;);
#endif #endif
/* Open boot drive */ /* Open boot drive */
if (!FsOpenVolume(BootDrive, BootPartition)) if (!FsOpenBootVolume())
{ {
#ifdef USE_UI #ifdef USE_UI
UiMessageBox("Failed to open boot drive."); UiMessageBox("Failed to open boot drive.");