Translate partition 0 to active partition. Fixes bug 181.
authorGé van Geldorp <ge@gse.nl>
Thu, 8 Sep 2005 08:29:01 +0000 (08:29 +0000)
committerGé van Geldorp <ge@gse.nl>
Thu, 8 Sep 2005 08:29:01 +0000 (08:29 +0000)
svn path=/trunk/; revision=17736

12 files changed:
reactos/boot/freeldr/freeldr/arch/i386/i386.h
reactos/boot/freeldr/freeldr/arch/i386/i386disk.c
reactos/boot/freeldr/freeldr/arch/i386/machpc.c
reactos/boot/freeldr/freeldr/arch/i386/machxbox.c
reactos/boot/freeldr/freeldr/disk/partition.c
reactos/boot/freeldr/freeldr/include/disk.h
reactos/boot/freeldr/freeldr/include/machine.h
reactos/boot/freeldr/freeldr/linuxboot.c
reactos/boot/freeldr/freeldr/machine.c
reactos/boot/freeldr/freeldr/miscboot.c
reactos/boot/freeldr/freeldr/reactos/arcname.c
reactos/boot/freeldr/freeldr/reactos/reactos.c

index cb76eda..90067bd 100644 (file)
@@ -34,6 +34,7 @@ extern BOOL i386DiskGetSystemVolume(char *SystemPath, char *RemainingPath,
 extern BOOL i386DiskGetBootPath(char *BootPath, unsigned Size);
 extern VOID i386DiskGetBootDevice(PULONG BootDevice);
 extern BOOL i386DiskBootingFromFloppy(VOID);
 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_ */
 
 
 #endif /* __I386_I386_H_ */
 
index a0669a0..0f79041 100644 (file)
@@ -165,6 +165,7 @@ BOOL DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT Buff
 
        memcpy(Buffer, Ptr, BufferSize);
 
 
        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]));
         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 @@ BOOL DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT Buff
         {
             DbgPrint((DPRINT_HB, "signature:                             %x\n", Ptr[15]));
         }
         {
             DbgPrint((DPRINT_HB, "signature:                             %x\n", Ptr[15]));
         }
+#endif
 
        return TRUE;
 }
 
        return TRUE;
 }
@@ -202,6 +204,7 @@ BOOL i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLON
 {
        PARTITION_TABLE_ENTRY   PartitionTableEntry;
        UCHAR                   VolumeType;
 {
        PARTITION_TABLE_ENTRY   PartitionTableEntry;
        UCHAR                   VolumeType;
+       ULONG                   ActivePartition;
 
        DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", i386BootDrive, i386BootPartition));
 
 
        DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", i386BootDrive, i386BootPartition));
 
@@ -234,7 +237,7 @@ BOOL i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLON
        if (i386BootPartition == 0)
        {
                // Partition requested was zero which means the boot partition
        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;
                {
                        /* Try partition-less disk */
                        *StartSector = 0;
@@ -460,6 +463,46 @@ i386DiskGetBootPath(char *BootPath, unsigned Size)
        return TRUE;
 }
 
        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 */
 #endif /* defined __i386__ */
 
 /* EOF */
index 8bbe0ca..eae1bb0 100644 (file)
@@ -54,6 +54,7 @@ PcMachInit(char *CmdLine)
   MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
   MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
   MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
   MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
   MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
   MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
+  MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
   MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
   MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry;
   MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
   MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
   MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry;
   MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
index bbb3ca8..fe3c6db 100644 (file)
@@ -52,6 +52,7 @@ XboxMachInit(char *CmdLine)
   MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
   MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
   MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
   MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
   MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
   MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
+  MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
   MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
   MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry;
   MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
   MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
   MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry;
   MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
index 1589cff..c353dba 100644 (file)
 #include <machine.h>
 
 
 #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                   BootablePartitionCount = 0;
-       ULONG                   ActivePartition = 0;
        MASTER_BOOT_RECORD      MasterBootRecord;
 
        MASTER_BOOT_RECORD      MasterBootRecord;
 
+       *ActivePartition = 0;
        // Read master boot record
        if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
        {
        // Read master boot record
        if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
        {
@@ -42,22 +44,22 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY Parti
        if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
        if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
-               ActivePartition = 0;
+               *ActivePartition = 1;
        }
        if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
        }
        if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
-               ActivePartition = 1;
+               *ActivePartition = 2;
        }
        if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
        }
        if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
-               ActivePartition = 2;
+               *ActivePartition = 3;
        }
        if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
        }
        if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80)
        {
                BootablePartitionCount++;
-               ActivePartition = 3;
+               *ActivePartition = 4;
        }
 
        // Make sure there was only one bootable partition
        }
 
        // Make sure there was only one bootable partition
@@ -73,7 +75,9 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY Parti
        }
 
        // Copy the partition table entry
        }
 
        // 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;
 }
 
        return TRUE;
 }
index 120289a..254d70f 100644 (file)
@@ -130,7 +130,7 @@ VOID        DiskStopFloppyMotor(VOID);      // Implemented in i386disk.c
 // Fixed Disk Partition Management Functions
 //
 ///////////////////////////////////////////////////////////////////////////////////////
 // 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);
 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);
index 06be431..08340f5 100644 (file)
@@ -61,6 +61,7 @@ typedef struct tagMACHVTBL
   BOOL (*DiskGetBootPath)(char *BootPath, unsigned Size);
   VOID (*DiskGetBootDevice)(PULONG BootDevice);
   BOOL (*DiskBootingFromFloppy)(VOID);
   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);
   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 @@ extern MACHVTBL MachVtbl;
 #define MachDiskGetBootPath(Path, Size)                MachVtbl.DiskGetBootPath((Path), (Size))
 #define MachDiskGetBootDevice(BootDevice)      MachVtbl.DiskGetBootDevice(BootDevice)
 #define MachDiskBootingFromFloppy()            MachVtbl.DiskBootingFromFloppy()
 #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))
 #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))
index 75246d5..e2bc48d 100644 (file)
@@ -81,6 +81,11 @@ VOID LoadAndBootLinux(PCHAR OperatingSystemName, PCHAR Description)
        }
 
        // Open the boot volume
        }
 
        // 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.");
        if (!FsOpenSystemVolume(LinuxBootPath, NULL, NULL))
        {
                UiMessageBox("Failed to open boot drive.");
index 99146d6..4940a92 100644 (file)
@@ -42,6 +42,7 @@
 #undef MachDiskGetBootPath
 #undef MachDiskGetBootDevice
 #undef MachDiskBootingFromFloppy
 #undef MachDiskGetBootPath
 #undef MachDiskGetBootDevice
 #undef MachDiskBootingFromFloppy
+#undef MachDiskNormalizeSystemPath
 #undef MachDiskReadLogicalSectors
 #undef MachDiskGetPartitionEntry
 #undef MachDiskGetDriveGeometry
 #undef MachDiskReadLogicalSectors
 #undef MachDiskGetPartitionEntry
 #undef MachDiskGetDriveGeometry
@@ -191,6 +192,12 @@ MachDiskBootingFromFloppy()
   return MachVtbl.DiskBootingFromFloppy();
 }
 
   return MachVtbl.DiskBootingFromFloppy();
 }
 
+BOOL
+MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size)
+{
+  return MachVtbl.DiskNormalizeSystemPath(SystemPath, Size);
+}
+
 BOOL
 MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
 {
 BOOL
 MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
 {
index 0df75e3..ff2cfe6 100644 (file)
@@ -54,6 +54,12 @@ VOID LoadAndBootBootSector(PCHAR OperatingSystemName)
                return;
        }
 
                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.");
        if (!FsOpenSystemVolume(FileName, FileName, NULL))
        {
                UiMessageBox("Failed to open boot drive.");
index 973b7e6..fd689c5 100644 (file)
@@ -73,7 +73,7 @@ BOOL DissectArcPath(CHAR *ArcPath, CHAR *BootPath, ULONG* BootDrive, ULONG* Boot
                p = p + 11;
                *BootPartition = atoi(p);
                p = strchr(p, ')');
                p = p + 11;
                *BootPartition = atoi(p);
                p = strchr(p, ')');
-               if ((p == NULL) || (*BootPartition == 0))
+               if (p == NULL)
                        return FALSE;
                p++;
        }
                        return FALSE;
                p++;
        }
index aa71e16..c617fc6 100644 (file)
@@ -671,6 +671,12 @@ LoadAndBootReactOS(PCHAR OperatingSystemName)
        }
        else
        {
        }
        else
        {
+               if (! MachDiskNormalizeSystemPath(SystemPath,
+                                                 sizeof(SystemPath)))
+               {
+                       UiMessageBox("Invalid system path");
+                       return;
+               }
                /* copy system path into kernel command line */
                strcpy(reactos_kernel_cmdline, SystemPath);
        }
                /* copy system path into kernel command line */
                strcpy(reactos_kernel_cmdline, SystemPath);
        }