Translate partition 0 to active partition. Fixes bug 181. Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386.h Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c Modified: trunk/reactos/boot/freeldr/freeldr/disk/partition.c Modified: trunk/reactos/boot/freeldr/freeldr/include/disk.h Modified: trunk/reactos/boot/freeldr/freeldr/include/machine.h Modified: trunk/reactos/boot/freeldr/freeldr/linuxboot.c Modified: trunk/reactos/boot/freeldr/freeldr/machine.c Modified: trunk/reactos/boot/freeldr/freeldr/miscboot.c Modified: trunk/reactos/boot/freeldr/freeldr/reactos/arcname.c Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c _____
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386.h --- trunk/reactos/boot/freeldr/freeldr/arch/i386/i386.h 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/i386.h 2005-09-08 08:29:01 UTC (rev 17736) @@ -34,6 +34,7 @@
extern BOOL i386DiskGetBootPath(char *BootPath, unsigned Size); extern VOID i386DiskGetBootDevice(PULONG BootDevice); extern BOOL i386DiskBootingFromFloppy(VOID); +extern BOOL i386DiskNormalizeSystemPath(char *SystemPath, unsigned Size);
#endif /* __I386_I386_H_ */
_____
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c --- trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -165,6 +165,7 @@
memcpy(Buffer, Ptr, BufferSize);
+#ifdef DEBUG DbgPrint((DPRINT_DISK, "size of buffer: %x\n", Ptr[0])); DbgPrint((DPRINT_DISK, "information flags: %x\n", Ptr[1])); DbgPrint((DPRINT_DISK, "number of physical cylinders on drive: %u\n", *(PULONG)&Ptr[2])); @@ -194,6 +195,7 @@ { DbgPrint((DPRINT_HB, "signature: %x\n", Ptr[15])); } +#endif
return TRUE; } @@ -202,6 +204,7 @@ { PARTITION_TABLE_ENTRY PartitionTableEntry; UCHAR VolumeType; + ULONG ActivePartition;
DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", i386BootDrive, i386BootPartition));
@@ -234,7 +237,7 @@ if (i386BootPartition == 0) { // Partition requested was zero which means the boot partition - if (! DiskGetActivePartitionEntry(i386BootDrive, &PartitionTableEntry)) + if (! DiskGetActivePartitionEntry(i386BootDrive, &PartitionTableEntry, &ActivePartition)) { /* Try partition-less disk */ *StartSector = 0; @@ -460,6 +463,46 @@ return TRUE; }
+BOOL +i386DiskNormalizeSystemPath(char *SystemPath, unsigned Size) +{ + CHAR BootPath[256]; + ULONG PartitionNumber; + ULONG DriveNumber; + PARTITION_TABLE_ENTRY PartEntry; + char *p; + + if (!DissectArcPath(SystemPath, BootPath, &DriveNumber, &PartitionNumber)) + { + return FALSE; + } + + if (0 != PartitionNumber) + { + return TRUE; + } + + if (! DiskGetActivePartitionEntry(DriveNumber, + &PartEntry, + &PartitionNumber) || + PartitionNumber < 1 || 9 < PartitionNumber) + { + return FALSE; + } + + p = SystemPath; + while ('\0' != *p && 0 != strnicmp(p, "partition(", 10)) { + p++; + } + p = strchr(p, ')'); + if (NULL == p || '0' != *(p - 1)) { + return FALSE; + } + *(p - 1) = '0' + PartitionNumber; + + return TRUE; +} + #endif /* defined __i386__ */
/* EOF */ _____
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c --- trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -54,6 +54,7 @@
MachVtbl.DiskGetBootPath = i386DiskGetBootPath; MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice; MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy; + MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath; MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors; MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry; MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry; _____
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c --- trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -52,6 +52,7 @@
MachVtbl.DiskGetBootPath = i386DiskGetBootPath; MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice; MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy; + MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath; MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors; MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry; MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry; _____
Modified: trunk/reactos/boot/freeldr/freeldr/disk/partition.c --- trunk/reactos/boot/freeldr/freeldr/disk/partition.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/disk/partition.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -26,12 +26,14 @@
#include <machine.h>
-BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry) +BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, + PPARTITION_TABLE_ENTRY PartitionTableEntry, + ULONG *ActivePartition) { ULONG BootablePartitionCount = 0; - ULONG ActivePartition = 0; MASTER_BOOT_RECORD MasterBootRecord;
+ *ActivePartition = 0; // Read master boot record if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord)) { @@ -42,22 +44,22 @@ if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80) { BootablePartitionCount++; - ActivePartition = 0; + *ActivePartition = 1; } if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80) { BootablePartitionCount++; - ActivePartition = 1; + *ActivePartition = 2; } if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80) { BootablePartitionCount++; - ActivePartition = 2; + *ActivePartition = 3; } if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80) { BootablePartitionCount++; - ActivePartition = 3; + *ActivePartition = 4; }
// Make sure there was only one bootable partition @@ -73,7 +75,9 @@ }
// Copy the partition table entry - RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[ActivePartition], sizeof(PARTITION_TABLE_ENTRY)); + RtlCopyMemory(PartitionTableEntry, + &MasterBootRecord.PartitionTable[*ActivePartition - 1], + sizeof(PARTITION_TABLE_ENTRY));
return TRUE; } _____
Modified: trunk/reactos/boot/freeldr/freeldr/include/disk.h --- trunk/reactos/boot/freeldr/freeldr/include/disk.h 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/include/disk.h 2005-09-08 08:29:01 UTC (rev 17736) @@ -130,7 +130,7 @@
// Fixed Disk Partition Management Functions //
//////////////////////////////////////////////////////////////////////// /////////////// -BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); +BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry, ULONG *ActivePartition); BOOL DiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOL DiskGetFirstPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOL DiskGetFirstExtendedPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry); _____
Modified: trunk/reactos/boot/freeldr/freeldr/include/machine.h --- trunk/reactos/boot/freeldr/freeldr/include/machine.h 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/include/machine.h 2005-09-08 08:29:01 UTC (rev 17736) @@ -61,6 +61,7 @@
BOOL (*DiskGetBootPath)(char *BootPath, unsigned Size); VOID (*DiskGetBootDevice)(PULONG BootDevice); BOOL (*DiskBootingFromFloppy)(VOID); + BOOL (*DiskNormalizeSystemPath)(char *SystemPath, unsigned Size); 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); @@ -97,6 +98,7 @@ #define MachDiskGetBootPath(Path, Size) MachVtbl.DiskGetBootPath((Path), (Size)) #define MachDiskGetBootDevice(BootDevice) MachVtbl.DiskGetBootDevice(BootDevice) #define MachDiskBootingFromFloppy() MachVtbl.DiskBootingFromFloppy() +#define MachDiskNormalizeSystemPath(Path, Size) MachVtbl.DiskNormalizeSystemPath((Path), (Size)) #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)) _____
Modified: trunk/reactos/boot/freeldr/freeldr/linuxboot.c --- trunk/reactos/boot/freeldr/freeldr/linuxboot.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/linuxboot.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -81,6 +81,11 @@
}
// Open the boot volume + if (!MachDiskNormalizeSystemPath(LinuxBootPath, sizeof(LinuxBootPath))) + { + UiMessageBox("Invalid boot path"); + goto LinuxBootFailed; + } if (!FsOpenSystemVolume(LinuxBootPath, NULL, NULL)) { UiMessageBox("Failed to open boot drive."); _____
Modified: trunk/reactos/boot/freeldr/freeldr/machine.c --- trunk/reactos/boot/freeldr/freeldr/machine.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/machine.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -42,6 +42,7 @@
#undef MachDiskGetBootPath #undef MachDiskGetBootDevice #undef MachDiskBootingFromFloppy +#undef MachDiskNormalizeSystemPath #undef MachDiskReadLogicalSectors #undef MachDiskGetPartitionEntry #undef MachDiskGetDriveGeometry @@ -192,6 +193,12 @@ }
BOOL +MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size) +{ + return MachVtbl.DiskNormalizeSystemPath(SystemPath, Size); +} + +BOOL MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer) { return MachVtbl.DiskReadLogicalSectors(DriveNumber, SectorNumber, SectorCount, Buffer); _____
Modified: trunk/reactos/boot/freeldr/freeldr/miscboot.c --- trunk/reactos/boot/freeldr/freeldr/miscboot.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/miscboot.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -54,6 +54,12 @@
return; }
+ if (!MachDiskNormalizeSystemPath(FileName, sizeof(FileName))) + { + UiMessageBox("Invalid path to boot sector file"); + return; + } + if (!FsOpenSystemVolume(FileName, FileName, NULL)) { UiMessageBox("Failed to open boot drive."); _____
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/arcname.c --- trunk/reactos/boot/freeldr/freeldr/reactos/arcname.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/reactos/arcname.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -73,7 +73,7 @@
p = p + 11; *BootPartition = atoi(p); p = strchr(p, ')'); - if ((p == NULL) || (*BootPartition == 0)) + if (p == NULL) return FALSE; p++; } _____
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c --- trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c 2005-09-08 06:52:01 UTC (rev 17735) +++ trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c 2005-09-08 08:29:01 UTC (rev 17736) @@ -671,6 +671,12 @@
} else { + if (! MachDiskNormalizeSystemPath(SystemPath, + sizeof(SystemPath))) + { + UiMessageBox("Invalid system path"); + return; + } /* copy system path into kernel command line */ strcpy(reactos_kernel_cmdline, SystemPath); }