[FREELDR]
authorCameron Gutman <aicommander@gmail.com>
Wed, 28 Apr 2010 03:07:21 +0000 (03:07 +0000)
committerCameron Gutman <aicommander@gmail.com>
Wed, 28 Apr 2010 03:07:21 +0000 (03:07 +0000)
- Remove the useless function MachDiskNormalizeSystemPath
- Rewrite DiskGetBootPath to be much less hacky (but still not hack free)
- Freeloader doesn't have to be installed on multi(0)disk(0)rdisk(0)partition(1) (IDE primary master) anymore :)
- Freeloader successfully booted ROS after loading itself from multi(0)disk(0)rdisk(1)partition(1)

svn path=/trunk/; revision=47052

12 files changed:
reactos/boot/freeldr/freeldr/arch/i386/machpc.c
reactos/boot/freeldr/freeldr/arch/i386/machxbox.c
reactos/boot/freeldr/freeldr/arch/i386/miscboot.c
reactos/boot/freeldr/freeldr/arch/powerpc/mach.c
reactos/boot/freeldr/freeldr/disk/disk.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/reactos/arcname.c
reactos/boot/freeldr/freeldr/reactos/reactos.c

index 74f3e22..1b985f2 100644 (file)
@@ -45,7 +45,6 @@ PcMachInit(const char *CmdLine)
     MachVtbl.PrepareForReactOS = PcPrepareForReactOS;
     MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
     MachVtbl.DiskGetBootPath = DiskGetBootPath;
-    MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
     MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
     MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
     MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount;
index 442c7be..704a7ae 100644 (file)
@@ -48,7 +48,6 @@ XboxMachInit(const char *CmdLine)
   MachVtbl.PrepareForReactOS = XboxPrepareForReactOS;
   MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
   MachVtbl.DiskGetBootPath = DiskGetBootPath;
-  MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
   MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
   MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
   MachVtbl.DiskGetCacheableBlockCount = XboxDiskGetCacheableBlockCount;
index e0aa98c..1f30141 100644 (file)
@@ -44,12 +44,6 @@ VOID LoadAndBootBootSector(PCSTR OperatingSystemName)
                return;
        }
 
-       if (!MachDiskNormalizeSystemPath(FileName, sizeof(FileName)))
-       {
-               UiMessageBox("Invalid path to boot sector file");
-               return;
-       }
-
        FilePointer = FsOpenFile(FileName);
        if (!FilePointer)
        {
index 57cacd2..9abd56b 100644 (file)
@@ -440,7 +440,6 @@ void PpcDefaultMachVtbl()
 
     MachVtbl.GetMemoryMap = PpcGetMemoryMap;
 
-    MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
     MachVtbl.DiskGetBootPath = PpcDiskGetBootPath;
     MachVtbl.DiskReadLogicalSectors = PpcDiskReadLogicalSectors;
     MachVtbl.DiskGetDriveGeometry = PpcDiskGetDriveGeometry;
index a5a6510..b7ce329 100644 (file)
@@ -107,62 +107,80 @@ DiskGetBootPath(char *BootPath, unsigned Size)
 {
        static char Path[] = "multi(0)disk(0)";
        char Device[4];
-    
-       _itoa(BootDrive, Device, 10);
-       if (Size <= sizeof(Path) + 6 + strlen(Device))
-       {
-               return FALSE;
-       }
-       strcpy(BootPath, Path);
-       strcat(BootPath, BootDrive < 0x80 ? "fdisk" : "cdrom");
-       strcat(strcat(strcat(BootPath, "("), Device), ")");
-    
-       if (strcmp(BootPath, "multi(0)disk(0)cdrom(128)") == 0)
-               strcpy(BootPath, "multi(0)disk(0)rdisk(0)partition(1)");
-       return TRUE;
-}
+       char Partition[4];
+       PARTITION_TABLE_ENTRY PartitionEntry;
+       MASTER_BOOT_RECORD MasterBootRecord;
 
-BOOLEAN
-DiskNormalizeSystemPath(char *SystemPath, unsigned Size)
-{
-       CHAR BootPath[256];
-       ULONG PartitionNumber;
-       ULONG DriveNumber;
-       PARTITION_TABLE_ENTRY PartEntry;
-       char *p;
-    
-       if (!DissectArcPath(SystemPath, BootPath, &DriveNumber, &PartitionNumber))
+       if (BootDrive < 0x80)
        {
-               return FALSE;
+               /* This is a floppy */
+
+               if (Size <= sizeof(Path) + 7 + strlen(Device))
+               {
+                       return FALSE;
+               }
+
+               strcpy(BootPath, Path);
+
+               strcat(BootPath, "fdisk");
+
+               _itoa(BootDrive, Device, 10);
+               strcat(BootPath, "(");
+               strcat(BootPath, Device);
+               strcat(BootPath, ")");
        }
-    
-       if (0 != PartitionNumber || DriveNumber < 0x80)
+       /* FIXME */
+       else if (DiskReadBootRecord(BootDrive, 0, &MasterBootRecord))
        {
-               return TRUE;
-       }
-    
-       if (! DiskGetActivePartitionEntry(DriveNumber,
-                                         &PartEntry,
-                                         &PartitionNumber) ||
-           PartitionNumber < 1 || 9 < PartitionNumber)
+               /* This is a hard disk */
+
+               if (!DiskGetActivePartitionEntry(BootDrive, &PartitionEntry, &BootPartition))
+               {
+                       DbgPrint("Invalid active partition information\n");
+                       return FALSE;
+               }
+
+               if (Size <= sizeof(Path) + 18 + strlen(Device) + strlen(Partition))
+               {
+                       return FALSE;
+               }
+
+               strcpy(BootPath, Path);
+
+               strcat(BootPath, "rdisk");
+
+               _itoa(BootDrive - 0x80, Device, 10);
+               strcat(BootPath, "(");
+               strcat(BootPath, Device);
+               strcat(BootPath, ")");
+
+               _itoa(BootPartition, Partition, 10);
+               strcat(BootPath, "partition(");
+               strcat(BootPath, Partition);
+               strcat(BootPath, ")");
+        }
+       else
        {
-               return FALSE;
-       }
-    
-       p = SystemPath;
-       while ('\0' != *p && 0 != _strnicmp(p, "partition(", 10)) {
-               p++;
-       }
-       p = strchr(p, ')');
-       if (NULL == p || '0' != *(p - 1)) {
-               return FALSE;
+               /* This is a CD-ROM drive */
+
+               if (Size <= sizeof(Path) + 7 + strlen(Device))
+               {
+                       return FALSE;
+               }
+
+               strcpy(BootPath, Path);
+
+               strcat(BootPath, "cdrom");
+
+               _itoa(BootDrive - 0x80, Device, 10);
+               strcat(BootPath, "(");
+               strcat(BootPath, Device);
+               strcat(BootPath, ")");
        }
-       *(p - 1) = '0' + PartitionNumber;
-    
+
        return TRUE;
 }
 
-
 // This function is in arch/i386/i386disk.c
 //VOID DiskStopFloppyMotor(VOID)
 
index 8966e67..b93b2e1 100644 (file)
@@ -197,7 +197,6 @@ BOOLEAN DiskGetFirstExtendedPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord,
 
 BOOLEAN DiskReadBootRecord(ULONG DriveNumber, ULONGLONG LogicalSectorNumber, PMASTER_BOOT_RECORD BootRecord)
 {
-       char            ErrMsg[64];
        ULONG           Index;
 
        // Read master boot record
@@ -231,9 +230,6 @@ BOOLEAN DiskReadBootRecord(ULONG DriveNumber, ULONGLONG LogicalSectorNumber, PMA
        // Check the partition table magic value
        if (BootRecord->MasterBootRecordMagic != 0xaa55)
        {
-               sprintf(ErrMsg, "Invalid partition table magic 0x%x found on drive 0x%lx",
-                       BootRecord->MasterBootRecordMagic, DriveNumber);
-               DiskError(ErrMsg, 0);
                return FALSE;
        }
 
index daaaa49..191ee12 100644 (file)
@@ -127,7 +127,6 @@ extern ULONG BootDrive;
 extern ULONG BootPartition;
 
 BOOLEAN DiskGetBootPath(char *BootPath, unsigned Size);
-BOOLEAN DiskNormalizeSystemPath(char *SystemPath, unsigned Size);
 
 
 ///////////////////////////////////////////////////////////////////////////////////////
index 0c0076f..6595205 100644 (file)
@@ -62,7 +62,6 @@ typedef struct tagMACHVTBL
   ULONG (*GetMemoryMap)(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize);
 
   BOOLEAN (*DiskGetBootPath)(char *BootPath, unsigned Size);
-  BOOLEAN (*DiskNormalizeSystemPath)(char *SystemPath, unsigned Size);
   BOOLEAN (*DiskReadLogicalSectors)(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
   BOOLEAN (*DiskGetDriveGeometry)(ULONG DriveNumber, PGEOMETRY DriveGeometry);
   ULONG (*DiskGetCacheableBlockCount)(ULONG DriveNumber);
index 10c2017..5aea40c 100644 (file)
@@ -97,13 +97,6 @@ VOID LoadAndBootLinux(PCSTR OperatingSystemName, PCSTR Description)
                goto LinuxBootFailed;
        }
 
-       // Open the boot volume
-       if (!MachDiskNormalizeSystemPath(LinuxBootPath, sizeof(LinuxBootPath)))
-       {
-               UiMessageBox("Invalid boot path");
-               goto LinuxBootFailed;
-       }
-
        // Open the kernel
        LinuxKernel = FsOpenFile(LinuxKernelName);
        if (!LinuxKernel)
index 9021a7c..c898bf4 100644 (file)
@@ -37,7 +37,6 @@
 #undef MachBeep
 #undef MachPrepareForReactOS
 #undef MachDiskGetBootPath
-#undef MachDiskNormalizeSystemPath
 #undef MachDiskReadLogicalSectors
 #undef MachDiskGetDriveGeometry
 #undef MachDiskGetCacheableBlockCount
@@ -152,12 +151,6 @@ MachDiskGetBootPath(char *BootPath, unsigned Size)
   return MachVtbl.DiskGetBootPath(BootPath, Size);
 }
 
-BOOLEAN
-MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size)
-{
-  return MachVtbl.DiskNormalizeSystemPath(SystemPath, Size);
-}
-
 BOOLEAN
 MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
 {
index 3fe1fc6..4b7f97a 100644 (file)
@@ -69,7 +69,7 @@ BOOLEAN DissectArcPath(CHAR *ArcPath, CHAR *BootPath, ULONG* BootDrive, ULONG* B
                 *  multi(0)disk(0)cdrom(x)\path
                 */
                p = p + 6;
-               *BootDrive = atoi(p);
+               *BootDrive = atoi(p) + 0x80;
                p = strchr(p, ')');
                if (p == NULL)
                        return FALSE;
index 12c8c66..81b654b 100644 (file)
@@ -718,12 +718,6 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
     }
     else
     {
-        if (! MachDiskNormalizeSystemPath(SystemPath,
-                                          sizeof(SystemPath)))
-        {
-            UiMessageBox("Invalid system path");
-            return;
-        }
         /* copy system path into kernel command line */
         strcpy(reactos_kernel_cmdline, SystemPath);
     }