Translate partition 0 to active partition. Fixes bug 181.

svn path=/trunk/; revision=17736
This commit is contained in:
Gé van Geldorp 2005-09-08 08:29:01 +00:00
parent 659c21724b
commit f2854a8641
12 changed files with 86 additions and 10 deletions

View 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 i386DiskNormalizeSystemPath(char *SystemPath, unsigned Size);
#endif /* __I386_I386_H_ */

View file

@ -165,6 +165,7 @@ BOOL DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT Buff
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 @@ BOOL DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT Buff
{
DbgPrint((DPRINT_HB, "signature: %x\n", Ptr[15]));
}
#endif
return TRUE;
}
@ -202,6 +204,7 @@ BOOL i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLON
{
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 @@ BOOL i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLON
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 @@ i386DiskGetBootPath(char *BootPath, unsigned Size)
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 */

View file

@ -54,6 +54,7 @@ PcMachInit(char *CmdLine)
MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry;
MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;

View file

@ -52,6 +52,7 @@ XboxMachInit(char *CmdLine)
MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry;
MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;

View file

@ -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 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY Parti
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 @@ BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY Parti
}
// 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;
}

View file

@ -130,7 +130,7 @@ VOID DiskStopFloppyMotor(VOID); // Implemented in i386disk.c
// 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);

View file

@ -61,6 +61,7 @@ typedef struct tagMACHVTBL
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 @@ extern MACHVTBL MachVtbl;
#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))

View file

@ -81,6 +81,11 @@ VOID LoadAndBootLinux(PCHAR OperatingSystemName, PCHAR Description)
}
// 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.");

View file

@ -42,6 +42,7 @@
#undef MachDiskGetBootPath
#undef MachDiskGetBootDevice
#undef MachDiskBootingFromFloppy
#undef MachDiskNormalizeSystemPath
#undef MachDiskReadLogicalSectors
#undef MachDiskGetPartitionEntry
#undef MachDiskGetDriveGeometry
@ -191,6 +192,12 @@ MachDiskBootingFromFloppy()
return MachVtbl.DiskBootingFromFloppy();
}
BOOL
MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size)
{
return MachVtbl.DiskNormalizeSystemPath(SystemPath, Size);
}
BOOL
MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
{

View file

@ -54,6 +54,12 @@ VOID LoadAndBootBootSector(PCHAR OperatingSystemName)
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.");

View file

@ -73,7 +73,7 @@ BOOL DissectArcPath(CHAR *ArcPath, CHAR *BootPath, ULONG* BootDrive, ULONG* Boot
p = p + 11;
*BootPartition = atoi(p);
p = strchr(p, ')');
if ((p == NULL) || (*BootPartition == 0))
if (p == NULL)
return FALSE;
p++;
}

View file

@ -671,6 +671,12 @@ LoadAndBootReactOS(PCHAR OperatingSystemName)
}
else
{
if (! MachDiskNormalizeSystemPath(SystemPath,
sizeof(SystemPath)))
{
UiMessageBox("Invalid system path");
return;
}
/* copy system path into kernel command line */
strcpy(reactos_kernel_cmdline, SystemPath);
}