From b55b368e310583f17e6b11f6a1796fe5c340aef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Tue, 26 Apr 2005 18:18:36 +0000 Subject: [PATCH] Re-apply 14698 - 14762 and fix resulting problem svn path=/trunk/; revision=14819 --- reactos/boot/freeldr/freeldr/arch/i386/arch.S | 85 +++--- .../boot/freeldr/freeldr/arch/i386/archmach.c | 6 +- reactos/boot/freeldr/freeldr/arch/i386/boot.S | 2 +- reactos/boot/freeldr/freeldr/arch/i386/i386.h | 40 +++ .../boot/freeldr/freeldr/arch/i386/i386disk.c | 244 +++++++++++++++++- .../boot/freeldr/freeldr/arch/i386/linux.S | 4 +- .../boot/freeldr/freeldr/arch/i386/machpc.c | 8 +- .../boot/freeldr/freeldr/arch/i386/machpc.h | 2 +- .../boot/freeldr/freeldr/arch/i386/machxbox.c | 8 +- .../boot/freeldr/freeldr/arch/i386/machxbox.h | 2 +- .../boot/freeldr/freeldr/arch/powerpc/mach.c | 2 +- reactos/boot/freeldr/freeldr/bootmgr.c | 7 + reactos/boot/freeldr/freeldr/disk/partition.c | 13 +- reactos/boot/freeldr/freeldr/freeldr.c | 2 +- reactos/boot/freeldr/freeldr/fs/fs.c | 140 ++++------ .../boot/freeldr/freeldr/include/freeldr.h | 2 - reactos/boot/freeldr/freeldr/include/fs.h | 3 +- .../freeldr/freeldr/{fs => include}/fsrec.h | 0 .../boot/freeldr/freeldr/include/machine.h | 12 +- reactos/boot/freeldr/freeldr/inifile/ini.h | 2 +- .../boot/freeldr/freeldr/inifile/ini_init.c | 33 +-- reactos/boot/freeldr/freeldr/linuxboot.c | 42 ++- reactos/boot/freeldr/freeldr/machine.c | 43 +++ reactos/boot/freeldr/freeldr/miscboot.c | 44 ++-- .../boot/freeldr/freeldr/reactos/arcname.c | 16 +- .../boot/freeldr/freeldr/reactos/reactos.c | 92 ++----- .../boot/freeldr/freeldr/reactos/setupldr.c | 25 +- 27 files changed, 564 insertions(+), 315 deletions(-) create mode 100644 reactos/boot/freeldr/freeldr/arch/i386/i386.h rename reactos/boot/freeldr/freeldr/{fs => include}/fsrec.h (100%) diff --git a/reactos/boot/freeldr/freeldr/arch/i386/arch.S b/reactos/boot/freeldr/freeldr/arch/i386/arch.S index bc334ef8004..9b93f899d0e 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/arch.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/arch.S @@ -47,10 +47,10 @@ EXTERN(RealEntryPoint) .code32 /* Store the boot drive */ - movb %dl,(_BootDrive) + movb %dl,(_i386BootDrive) /* Store the boot partition */ - movb %dh,(_BootPartition) + movb %dh,(_i386BootPartition) /* GO! */ xorl %eax,%eax @@ -275,9 +275,11 @@ EXTERN(_DisableA20) * other boot loaders like Grub */ +#define MB_INFO_SIZE 90 #define MB_INFO_FLAGS_OFFSET 0 #define MB_INFO_BOOT_DEVICE_OFFSET 12 #define MB_INFO_COMMAND_LINE_OFFSET 16 +#define CMDLINE_SIZE 256 /* * 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 * ourself to 0x8000 */ -#define CMDLINE_BASE 0x7000 #define FREELDR_BASE 0x8000 #define INITIAL_BASE 0x200000 @@ -328,6 +329,31 @@ mb1: movw %dx,%ds 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 */ movl $INITIAL_BASE,%esi movl $FREELDR_BASE,%edi @@ -342,8 +368,8 @@ mb1: /* Clear prefetch queue & correct CS, * jump to low mem */ - ljmp $PMODE_CS, $mb2 -mb2: + ljmp $PMODE_CS, $mb4 +mb4: /* Reload segment selectors */ movw $PMODE_DS,%dx movw %dx,%ds @@ -353,39 +379,28 @@ mb2: movw %dx,%ss movl $STACK32ADDR,%esp - /* Check for valid multiboot signature */ - cmpl $MULTIBOOT_BOOTLOADER_MAGIC,%eax - jne mbfail - + movl $mb_info,%ebx /* See if the boot device was passed in */ movl MB_INFO_FLAGS_OFFSET(%ebx),%edx testl $MB_INFO_FLAG_BOOT_DEVICE,%edx - jz mb3 + jz mb5 /* Retrieve boot device info */ movl MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax shrl $16,%eax incb %al - movb %al,_BootPartition - movb %ah,_BootDrive - jmp mb4 -mb3: /* No boot device known, assume first partition of first harddisk */ - movb $0x80,_BootDrive - movb $1,_BootPartition -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 + movb %al,_i386BootPartition + movb %ah,_i386BootDrive + jmp mb6 +mb5: /* No boot device known, assume first partition of first harddisk */ + movb $0x80,_i386BootDrive + movb $1,_i386BootPartition 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! */ pushl %eax @@ -462,8 +477,14 @@ rmode_idtptr: .word 0x3ff /* Limit */ .long 0 /* Base Address */ -EXTERN(_BootDrive) +EXTERN(_i386BootDrive) .long 0 -EXTERN(_BootPartition) +EXTERN(_i386BootPartition) .long 0 + +mb_info: + .fill MB_INFO_SIZE, 1, 0 + +cmdline: + .fill CMDLINE_SIZE, 1, 0 diff --git a/reactos/boot/freeldr/freeldr/arch/i386/archmach.c b/reactos/boot/freeldr/freeldr/arch/i386/archmach.c index 347d8f56e22..c8171b0208c 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/archmach.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/archmach.c @@ -27,7 +27,7 @@ #include "rtl.h" VOID -MachInit(VOID) +MachInit(char *CmdLine) { ULONG PciId; @@ -39,11 +39,11 @@ MachInit(VOID) PciId = READ_PORT_ULONG((ULONG*) 0xcfc); if (0x02a510de == PciId) { - XboxMachInit(); + XboxMachInit(CmdLine); } else { - PcMachInit(); + PcMachInit(CmdLine); } HalpCalibrateStallExecution(); diff --git a/reactos/boot/freeldr/freeldr/arch/i386/boot.S b/reactos/boot/freeldr/freeldr/arch/i386/boot.S index ef465851862..3fb9bbb3a41 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/boot.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/boot.S @@ -31,7 +31,7 @@ EXTERN(_ChainLoadBiosBootSectorCode) .code16 /* Set the boot drive */ - movb (_BootDrive),%dl + movb (_i386BootDrive),%dl /* Load segment registers */ cli diff --git a/reactos/boot/freeldr/freeldr/arch/i386/i386.h b/reactos/boot/freeldr/freeldr/arch/i386/i386.h new file mode 100644 index 00000000000..cb76edaf0f5 --- /dev/null +++ b/reactos/boot/freeldr/freeldr/arch/i386/i386.h @@ -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 */ diff --git a/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c b/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c index cc0bdb3ffc7..b7b3a50587a 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c @@ -19,6 +19,8 @@ #include "freeldr.h" #include "debug.h" +#include "i386.h" +#include "fsrec.h" ///////////////////////////////////////////////////////////////////////////////////////////// // FUNCTIONS @@ -166,4 +168,244 @@ BOOL DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT Buff 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 */ diff --git a/reactos/boot/freeldr/freeldr/arch/i386/linux.S b/reactos/boot/freeldr/freeldr/arch/i386/linux.S index 16a5a001f2d..43c1c201fa2 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/linux.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/linux.S @@ -30,7 +30,7 @@ EXTERN(_BootNewLinuxKernel) .code16 /* Set the boot drive */ - movb (_BootDrive),%dl + movb (_i386BootDrive),%dl /* Load segment registers */ cli @@ -66,7 +66,7 @@ EXTERN(_BootOldLinuxKernel) .code16 /* Set the boot drive */ - movb (_BootDrive),%dl + movb (_i386BootDrive),%dl /* Load segment registers */ cli diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c index 0a6fa2840ed..8bbe0cadbc8 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c @@ -23,9 +23,10 @@ #include "machine.h" #include "machpc.h" #include "rtl.h" +#include "i386.h" VOID -PcMachInit(VOID) +PcMachInit(char *CmdLine) { EnableA20(); @@ -48,6 +49,11 @@ PcMachInit(VOID) MachVtbl.VideoSync = PcVideoSync; MachVtbl.VideoPrepareForReactOS = PcVideoPrepareForReactOS; MachVtbl.GetMemoryMap = PcMemGetMemoryMap; + MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume; + MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume; + MachVtbl.DiskGetBootPath = i386DiskGetBootPath; + MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice; + MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy; MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors; MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry; MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry; diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machpc.h b/reactos/boot/freeldr/freeldr/arch/i386/machpc.h index 5462a10effa..7a2a6eb58b8 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machpc.h +++ b/reactos/boot/freeldr/freeldr/arch/i386/machpc.h @@ -26,7 +26,7 @@ #include "mm.h" #endif -VOID PcMachInit(VOID); +VOID PcMachInit(char *CmdLine); VOID PcConsPutChar(int Ch); BOOL PcConsKbHit(); diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c index dd44d36ab73..bbb3ca86f44 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c @@ -21,9 +21,10 @@ #include "mm.h" #include "machine.h" #include "machxbox.h" +#include "i386.h" VOID -XboxMachInit(VOID) +XboxMachInit(char *CmdLine) { /* Initialize our stuff */ XboxMemInit(); @@ -46,6 +47,11 @@ XboxMachInit(VOID) MachVtbl.VideoSync = XboxVideoSync; MachVtbl.VideoPrepareForReactOS = XboxVideoPrepareForReactOS; MachVtbl.GetMemoryMap = XboxMemGetMemoryMap; + MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume; + MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume; + MachVtbl.DiskGetBootPath = i386DiskGetBootPath; + MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice; + MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy; MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors; MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry; MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry; diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h index 845f242e8b0..d82cdc8f246 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h +++ b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h @@ -26,7 +26,7 @@ UCHAR XboxFont8x16[256 * 16]; -VOID XboxMachInit(VOID); +VOID XboxMachInit(char *CmdLine); VOID XboxConsPutChar(int Ch); BOOL XboxConsKbHit(); diff --git a/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c b/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c index b5405cc2864..071ec9ebe17 100644 --- a/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c +++ b/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c @@ -279,7 +279,7 @@ void PpcInit( of_proxy the_ofproxy ) { BootMain("freeldr-ppc"); } -void MachInit() { +void MachInit(char *CmdLine) { int len; printf( "Determining boot device:\n" ); len = ofw_getprop(chosen_package, "bootpath", diff --git a/reactos/boot/freeldr/freeldr/bootmgr.c b/reactos/boot/freeldr/freeldr/bootmgr.c index 01cd5212462..fa7f3a47e23 100644 --- a/reactos/boot/freeldr/freeldr/bootmgr.c +++ b/reactos/boot/freeldr/freeldr/bootmgr.c @@ -49,6 +49,13 @@ VOID RunLoader(VOID) LONG TimeOut; ULONG SelectedOperatingSystem; + if (!FsOpenBootVolume()) + { + printf("Error opening boot partition for file access.\n"); + MachConsGetCh(); + return; + } + if (!IniFileInitialize()) { printf("Press any key to reboot.\n"); diff --git a/reactos/boot/freeldr/freeldr/disk/partition.c b/reactos/boot/freeldr/freeldr/disk/partition.c index 4c1aa01c035..42d1f0ab6de 100644 --- a/reactos/boot/freeldr/freeldr/disk/partition.c +++ b/reactos/boot/freeldr/freeldr/disk/partition.c @@ -28,7 +28,8 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry) { - ULONG BootablePartitionCount = 0; + ULONG BootablePartitionCount = 0; + ULONG ActivePartition = 0; MASTER_BOOT_RECORD MasterBootRecord; // Read master boot record @@ -41,22 +42,22 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY Parti if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80) { BootablePartitionCount++; - BootPartition = 0; + ActivePartition = 0; } if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80) { BootablePartitionCount++; - BootPartition = 1; + ActivePartition = 1; } if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80) { BootablePartitionCount++; - BootPartition = 2; + ActivePartition = 2; } if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80) { BootablePartitionCount++; - BootPartition = 3; + ActivePartition = 3; } // 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 - RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[BootPartition], sizeof(PARTITION_TABLE_ENTRY)); + RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[ActivePartition], sizeof(PARTITION_TABLE_ENTRY)); return TRUE; } diff --git a/reactos/boot/freeldr/freeldr/freeldr.c b/reactos/boot/freeldr/freeldr/freeldr.c index d1a6b5675de..0a2259a67c9 100644 --- a/reactos/boot/freeldr/freeldr/freeldr.c +++ b/reactos/boot/freeldr/freeldr/freeldr.c @@ -31,7 +31,7 @@ VOID BootMain(char *CmdLine) { CmdLineParse(CmdLine); - MachInit(); + MachInit(CmdLine); DebugInit(); diff --git a/reactos/boot/freeldr/freeldr/fs/fs.c b/reactos/boot/freeldr/freeldr/fs/fs.c index c91813f95d6..7bb4488e560 100644 --- a/reactos/boot/freeldr/freeldr/fs/fs.c +++ b/reactos/boot/freeldr/freeldr/fs/fs.c @@ -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. * 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 VolumeType; + UCHAR ErrorText[80]; - DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", DriveNumber, PartitionNumber)); + FsType = Type; - // Check and see if it is a floppy drive - // If so then just assume FAT12 file system type - if (DiskIsDriveRemovable(DriveNumber)) + switch (FsType) { - DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n")); - - FsType = FS_FAT; - return FatOpenVolume(DriveNumber, 0, 0); - } - - // 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")); - - FsType = FS_ISO9660; + case FS_FAT: + return FatOpenVolume(DriveNumber, StartSector, SectorCount); + case FS_EXT2: + return Ext2OpenVolume(DriveNumber, StartSector); + case FS_NTFS: + return NtfsOpenVolume(DriveNumber, StartSector); + case FS_ISO9660: 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: FsType = 0; - sprintf(ErrorText, "Unsupported file system. Type: 0x%x", VolumeType); + sprintf(ErrorText, "Unsupported file system. Type: 0x%x", Type); 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 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 FileHandle = NULL; diff --git a/reactos/boot/freeldr/freeldr/include/freeldr.h b/reactos/boot/freeldr/freeldr/include/freeldr.h index 3b41ac30190..c9082ae75ae 100644 --- a/reactos/boot/freeldr/freeldr/include/freeldr.h +++ b/reactos/boot/freeldr/freeldr/include/freeldr.h @@ -38,8 +38,6 @@ #define ROUND_DOWN(N, S) ((N) & ~((S) - 1)) #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 */ VOID BootMain(LPSTR CmdLine); diff --git a/reactos/boot/freeldr/freeldr/include/fs.h b/reactos/boot/freeldr/freeldr/include/fs.h index 6b2d57d774a..2af910ee4a8 100644 --- a/reactos/boot/freeldr/freeldr/include/fs.h +++ b/reactos/boot/freeldr/freeldr/include/fs.h @@ -33,7 +33,8 @@ #define PFILE FILE * VOID FileSystemError(PUCHAR ErrorString); -BOOL FsOpenVolume(ULONG DriveNumber, ULONG PartitionNumber); +BOOL FsOpenBootVolume(); +BOOL FsOpenSystemVolume(char *SystemPath, char *RemainingPath, PULONG BootDevice); PFILE FsOpenFile(PUCHAR FileName); VOID FsCloseFile(PFILE FileHandle); BOOL FsReadFile(PFILE FileHandle, ULONG BytesToRead, ULONG* BytesRead, PVOID Buffer); diff --git a/reactos/boot/freeldr/freeldr/fs/fsrec.h b/reactos/boot/freeldr/freeldr/include/fsrec.h similarity index 100% rename from reactos/boot/freeldr/freeldr/fs/fsrec.h rename to reactos/boot/freeldr/freeldr/include/fsrec.h diff --git a/reactos/boot/freeldr/freeldr/include/machine.h b/reactos/boot/freeldr/freeldr/include/machine.h index 2642ed57f8e..5879d2ef466 100644 --- a/reactos/boot/freeldr/freeldr/include/machine.h +++ b/reactos/boot/freeldr/freeldr/include/machine.h @@ -56,6 +56,11 @@ typedef struct tagMACHVTBL 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 (*DiskGetPartitionEntry)(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOL (*DiskGetDriveGeometry)(ULONG DriveNumber, PGEOMETRY DriveGeometry); @@ -66,7 +71,7 @@ typedef struct tagMACHVTBL VOID (*HwDetect)(VOID); } MACHVTBL, *PMACHVTBL; -VOID MachInit(VOID); +VOID MachInit(char *CmdLine); extern MACHVTBL MachVtbl; @@ -87,6 +92,11 @@ extern MACHVTBL MachVtbl; #define MachVideoSync() MachVtbl.VideoSync() #define MachVideoPrepareForReactOS() MachVtbl.VideoPrepareForReactOS() #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 MachDiskGetPartitionEntry(Drive, Part, Entry) MachVtbl.DiskGetPartitionEntry((Drive), (Part), (Entry)) #define MachDiskGetDriveGeometry(Drive, Geom) MachVtbl.DiskGetDriveGeometry((Drive), (Geom)) diff --git a/reactos/boot/freeldr/freeldr/inifile/ini.h b/reactos/boot/freeldr/freeldr/inifile/ini.h index 98a74967d33..64bd0388a50 100644 --- a/reactos/boot/freeldr/freeldr/inifile/ini.h +++ b/reactos/boot/freeldr/freeldr/inifile/ini.h @@ -57,7 +57,7 @@ extern PINI_SECTION IniFileSectionListHead; extern ULONG IniFileSectionCount; extern ULONG IniFileSettingCount; -PFILE IniOpenIniFile(UCHAR BootDriveNumber, UCHAR BootPartitionNumber); +PFILE IniOpenIniFile(); BOOL IniParseFile(PUCHAR IniFileData, ULONG IniFileSize); ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset); diff --git a/reactos/boot/freeldr/freeldr/inifile/ini_init.c b/reactos/boot/freeldr/freeldr/inifile/ini_init.c index 046133e4c1b..b145c116dcc 100644 --- a/reactos/boot/freeldr/freeldr/inifile/ini_init.c +++ b/reactos/boot/freeldr/freeldr/inifile/ini_init.c @@ -33,22 +33,7 @@ BOOL IniFileInitialize(VOID) BOOL Success; // Open freeldr.ini - // BootDrive & BootPartition are passed - // 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; - } + Freeldr_Ini = IniOpenIniFile(); if (Freeldr_Ini == NULL) { @@ -87,24 +72,10 @@ BOOL IniFileInitialize(VOID) return Success; } -PFILE IniOpenIniFile(UCHAR BootDriveNumber, UCHAR BootPartitionNumber) +PFILE IniOpenIniFile() { 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 IniFileHandle = FsOpenFile("freeldr.ini"); diff --git a/reactos/boot/freeldr/freeldr/linuxboot.c b/reactos/boot/freeldr/freeldr/linuxboot.c index fa1df78f337..255c9ea4820 100644 --- a/reactos/boot/freeldr/freeldr/linuxboot.c +++ b/reactos/boot/freeldr/freeldr/linuxboot.c @@ -40,18 +40,19 @@ PLINUX_BOOTSECTOR LinuxBootSector = NULL; PLINUX_SETUPSECTOR LinuxSetupSector = NULL; -ULONG SetupSectorSize = 0; -BOOL NewStyleLinuxKernel = FALSE; -ULONG LinuxKernelSize = 0; -ULONG LinuxInitrdSize = 0; -UCHAR LinuxKernelName[260]; -UCHAR LinuxInitrdName[260]; -BOOL LinuxHasInitrd = FALSE; -UCHAR LinuxCommandLine[260] = ""; -ULONG LinuxCommandLineSize = 0; -PVOID LinuxKernelLoadAddress = NULL; -PVOID LinuxInitrdLoadAddress = NULL; -UCHAR LinuxBootDescription[80]; +ULONG SetupSectorSize = 0; +BOOL NewStyleLinuxKernel = FALSE; +ULONG LinuxKernelSize = 0; +ULONG LinuxInitrdSize = 0; +UCHAR LinuxKernelName[260]; +UCHAR LinuxInitrdName[260]; +BOOL LinuxHasInitrd = FALSE; +UCHAR LinuxCommandLine[260] = ""; +ULONG LinuxCommandLineSize = 0; +PVOID LinuxKernelLoadAddress = NULL; +PVOID LinuxInitrdLoadAddress = NULL; +UCHAR LinuxBootDescription[80]; +UCHAR LinuxBootPath[260] = ""; VOID LoadAndBootLinux(PUCHAR OperatingSystemName, PUCHAR Description) { @@ -80,7 +81,7 @@ VOID LoadAndBootLinux(PUCHAR OperatingSystemName, PUCHAR Description) } // Open the boot volume - if (!FsOpenVolume(BootDrive, BootPartition)) + if (!FsOpenSystemVolume(LinuxBootPath, NULL, NULL)) { UiMessageBox("Failed to open boot drive."); goto LinuxBootFailed; @@ -226,8 +227,7 @@ LinuxBootFailed: BOOL LinuxParseIniSection(PUCHAR OperatingSystemName) { UCHAR SettingName[260]; - UCHAR SettingValue[260]; - ULONG SectionId; + ULONG SectionId; // Find all the message box settings and run them UiShowMessageBoxesInSection(OperatingSystemName); @@ -240,20 +240,12 @@ BOOL LinuxParseIniSection(PUCHAR OperatingSystemName) 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; } - BootDrive = DriveMapGetBiosDriveNumber(SettingValue); - - BootPartition = 0; - if (IniReadSettingByName(SectionId, "BootPartition", SettingValue, 260)) - { - BootPartition = atoi(SettingValue); - } - // Get the kernel name if (!IniReadSettingByName(SectionId, "Kernel", LinuxKernelName, 260)) { diff --git a/reactos/boot/freeldr/freeldr/machine.c b/reactos/boot/freeldr/freeldr/machine.c index 520769e3b06..99146d6c249 100644 --- a/reactos/boot/freeldr/freeldr/machine.c +++ b/reactos/boot/freeldr/freeldr/machine.c @@ -37,6 +37,11 @@ #undef MachVideoSync #undef MachVideoPrepareForReactOS #undef MachGetMemoryMap +#undef MachDiskGetBootVolume +#undef MachDiskGetSystemVolume +#undef MachDiskGetBootPath +#undef MachDiskGetBootDevice +#undef MachDiskBootingFromFloppy #undef MachDiskReadLogicalSectors #undef MachDiskGetPartitionEntry #undef MachDiskGetDriveGeometry @@ -148,6 +153,44 @@ MachGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG 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 MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer) { diff --git a/reactos/boot/freeldr/freeldr/miscboot.c b/reactos/boot/freeldr/freeldr/miscboot.c index 3531fe254f0..3d592fd4597 100644 --- a/reactos/boot/freeldr/freeldr/miscboot.c +++ b/reactos/boot/freeldr/freeldr/miscboot.c @@ -33,10 +33,9 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName) { PFILE FilePointer; UCHAR SettingName[80]; - UCHAR SettingValue[80]; - ULONG SectionId; + ULONG SectionId; UCHAR FileName[260]; - ULONG BytesRead; + ULONG BytesRead; // Find all the message box settings and run them UiShowMessageBoxesInSection(OperatingSystemName); @@ -49,27 +48,13 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName) 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)) { UiMessageBox("Boot sector file not specified for selected OS!"); return; } - if (!FsOpenVolume(BootDrive, BootPartition)) + if (!FsOpenSystemVolume(FileName, FileName, NULL)) { UiMessageBox("Failed to open boot drive."); return; @@ -111,10 +96,12 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName) VOID LoadAndBootPartition(PUCHAR OperatingSystemName) { - UCHAR SettingName[80]; - UCHAR SettingValue[80]; - ULONG SectionId; + UCHAR SettingName[80]; + UCHAR SettingValue[80]; + ULONG SectionId; PARTITION_TABLE_ENTRY PartitionTableEntry; + ULONG DriveNumber; + ULONG PartitionNumber; // Find all the message box settings and run them UiShowMessageBoxesInSection(OperatingSystemName); @@ -134,7 +121,7 @@ VOID LoadAndBootPartition(PUCHAR OperatingSystemName) return; } - BootDrive = DriveMapGetBiosDriveNumber(SettingValue); + DriveNumber = DriveMapGetBiosDriveNumber(SettingValue); // Read the boot partition if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80)) @@ -143,17 +130,17 @@ VOID LoadAndBootPartition(PUCHAR OperatingSystemName) return; } - BootPartition = atoi(SettingValue); + PartitionNumber = atoi(SettingValue); // Get the partition table entry - if (!DiskGetPartitionEntry(BootDrive, BootPartition, &PartitionTableEntry)) + if (!DiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry)) { return; } // Now try to read the partition boot sector // If this fails then abort - if (!MachDiskReadLogicalSectors(BootDrive, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00)) + if (!MachDiskReadLogicalSectors(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00)) { return; } @@ -182,7 +169,8 @@ VOID LoadAndBootDrive(PUCHAR OperatingSystemName) { UCHAR SettingName[80]; UCHAR SettingValue[80]; - ULONG SectionId; + ULONG SectionId; + ULONG DriveNumber; // Find all the message box settings and run them UiShowMessageBoxesInSection(OperatingSystemName); @@ -201,11 +189,11 @@ VOID LoadAndBootDrive(PUCHAR OperatingSystemName) return; } - BootDrive = DriveMapGetBiosDriveNumber(SettingValue); + DriveNumber = DriveMapGetBiosDriveNumber(SettingValue); // Now try to read the boot sector (or mbr) // If this fails then abort - if (!MachDiskReadLogicalSectors(BootDrive, 0, 1, (PVOID)0x7C00)) + if (!MachDiskReadLogicalSectors(DriveNumber, 0, 1, (PVOID)0x7C00)) { return; } diff --git a/reactos/boot/freeldr/freeldr/reactos/arcname.c b/reactos/boot/freeldr/freeldr/reactos/arcname.c index 9b1f1487cca..f65ca5b26cc 100644 --- a/reactos/boot/freeldr/freeldr/reactos/arcname.c +++ b/reactos/boot/freeldr/freeldr/reactos/arcname.c @@ -43,7 +43,21 @@ BOOL DissectArcPath(char *ArcPath, char *BootPath, ULONG* BootDrive, ULONG* Boot if (p == NULL) return FALSE; 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) { diff --git a/reactos/boot/freeldr/freeldr/reactos/reactos.c b/reactos/boot/freeldr/freeldr/reactos/reactos.c index 9cafa6a17da..df4561271fc 100644 --- a/reactos/boot/freeldr/freeldr/reactos/reactos.c +++ b/reactos/boot/freeldr/freeldr/reactos/reactos.c @@ -15,16 +15,6 @@ #define NDEBUG #include -#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 STDCALL FrLdrLoadKernel(PCHAR szFileName, @@ -564,6 +554,7 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName) PFILE FilePointer; CHAR name[1024]; CHAR value[1024]; + CHAR SystemPath[1024]; CHAR szKernelName[1024]; CHAR szHalName[1024]; CHAR szFileName[1024]; @@ -574,9 +565,6 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName) ULONG_PTR Base; ULONG Size; - - PARTITION_TABLE_ENTRY PartitionTableEntry; - ULONG rosPartition; extern ULONG PageDirectoryStart; extern ULONG PageDirectoryEnd; @@ -645,7 +633,7 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName) /* * 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."); return; @@ -654,62 +642,20 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName) /* * Special case for Live CD. */ - if (!stricmp(value, "LiveCD")) + if (!stricmp(SystemPath, "LiveCD")) { - strcpy(szBootPath, "\\reactos"); - - /* Set kernel command line */ - sprintf(multiboot_kernel_cmdline, - "multi(0)disk(0)cdrom(%u)\\reactos /MININT", - (unsigned int)BootDrive); + /* Normalize */ + MachDiskGetBootPath(SystemPath, sizeof(SystemPath)); + strcat(SystemPath, "\\reactos"); + strcat(strcpy(multiboot_kernel_cmdline, SystemPath), + " /MININT"); } else { - /* - * Verify system path - */ - 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); + /* copy system path into kernel command line */ + strcpy(multiboot_kernel_cmdline, SystemPath); } - /* Set boot drive and partition */ - ((LPSTR )(&LoaderBlock.BootDevice))[0] = (CHAR)BootDrive; - ((LPSTR )(&LoaderBlock.BootDevice))[1] = (CHAR)BootPartition; - /* * Read the optional kernel parameters (if any) */ @@ -719,13 +665,6 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName) 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(); UiDrawStatusText("Detecting Hardware..."); @@ -741,14 +680,21 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName) 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."); 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 * and try to load the kernel off the disk diff --git a/reactos/boot/freeldr/freeldr/reactos/setupldr.c b/reactos/boot/freeldr/freeldr/reactos/setupldr.c index bc2fe82e964..3571447ad37 100644 --- a/reactos/boot/freeldr/freeldr/reactos/setupldr.c +++ b/reactos/boot/freeldr/freeldr/reactos/setupldr.c @@ -312,13 +312,11 @@ VOID RunLoader(VOID) UiDrawStatusText(""); #endif - /* set boot drive and partition */ - ((char *)(&LoaderBlock.BootDevice))[0] = (char)BootDrive; - ((char *)(&LoaderBlock.BootDevice))[1] = (char)BootPartition; - + /* set boot device */ + MachDiskGetBootDevice(&LoaderBlock.BootDevice); /* Open boot drive */ - if (!FsOpenVolume(BootDrive, BootPartition)) + if (!FsOpenBootVolume()) { #ifdef USE_UI UiMessageBox("Failed to open boot drive."); @@ -330,7 +328,7 @@ VOID RunLoader(VOID) /* Open 'txtsetup.sif' */ if (!InfOpenFile (&InfHandle, - (BootDrive < 0x80) ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif", + MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif", &ErrorLine)) { printf("Failed to open 'txtsetup.sif'\n"); @@ -358,7 +356,7 @@ VOID RunLoader(VOID) printf("LoadOptions: '%s'\n", LoadOptions); #endif - if (BootDrive < 0x80) + if (MachDiskBootingFromFloppy()) { /* Boot from floppy disk */ SourcePath = "\\"; @@ -370,12 +368,9 @@ VOID RunLoader(VOID) } /* Set kernel command line */ - sprintf(multiboot_kernel_cmdline, - "multi(0)disk(0)%s(%u)%s %s", - (BootDrive < 0x80) ? "fdisk" : "cdrom", - (unsigned int)BootDrive, - SourcePath, - LoadOptions); + MachDiskGetBootPath(multiboot_kernel_cmdline, sizeof(multiboot_kernel_cmdline)); + strcat(strcat(strcat(multiboot_kernel_cmdline, SourcePath), " "), + LoadOptions); /* Load ntoskrnl.exe */ if (!LoadKernel(SourcePath, "ntoskrnl.exe")) @@ -400,7 +395,7 @@ for(;;); #endif /* Insert boot disk 2 */ - if (BootDrive < 0x80) + if (MachDiskBootingFromFloppy()) { #ifdef USE_UI UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER"); @@ -410,7 +405,7 @@ for(;;); #endif /* Open boot drive */ - if (!FsOpenVolume(BootDrive, BootPartition)) + if (!FsOpenBootVolume()) { #ifdef USE_UI UiMessageBox("Failed to open boot drive.");