Make disk partition handling architecture dependent, as not
[reactos.git] / reactos / boot / freeldr / freeldr / reactos / reactos.c
index 9cafa6a..df45612 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
-#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