There was no reason to have most of the i386Disk routines as i386-only routines,...
authorReactOS Portable Systems Group <ros-arm-bringup@svn.reactos.org>
Thu, 7 Feb 2008 00:43:09 +0000 (00:43 +0000)
committerReactOS Portable Systems Group <ros-arm-bringup@svn.reactos.org>
Thu, 7 Feb 2008 00:43:09 +0000 (00:43 +0000)
Made the ARM code use the shared disk routines, which allowed us to remove some hacks -> we now detect the boot/system volume just like on x86.
FreeLDR now loads NTOSKRNL.EXE on ARM.
Also made the DiskIsBootDeviceFloppy return FALSE for ramdisks.
Finally, note that the disk routines were still kept as Machine-specific routines in the Mach Table, so other architectures can still override them if they really need to (for example, the XBOX port overrides one of them for a specific XBOX hack).

svn path=/trunk/; revision=32173

12 files changed:
reactos/boot/freeldr/freeldr/arch/arm/stubs.c
reactos/boot/freeldr/freeldr/arch/i386/arch.S
reactos/boot/freeldr/freeldr/arch/i386/boot.S
reactos/boot/freeldr/freeldr/arch/i386/i386disk.c
reactos/boot/freeldr/freeldr/arch/i386/linux.S
reactos/boot/freeldr/freeldr/arch/i386/machpc.c
reactos/boot/freeldr/freeldr/arch/i386/machxbox.c
reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c
reactos/boot/freeldr/freeldr/disk/disk.c
reactos/boot/freeldr/freeldr/disk/ramdisk.c
reactos/boot/freeldr/freeldr/include/arch/i386/i386.h
reactos/boot/freeldr/freeldr/include/disk.h

index 70345a0..e8375d0 100644 (file)
@@ -24,7 +24,6 @@ FrLdrStartup(IN ULONG Magic)
     //
 }
 
-
 BOOLEAN
 ArmDiskGetDriveGeometry(IN ULONG DriveNumber,
                         OUT PGEOMETRY Geometry)
@@ -50,69 +49,41 @@ ArmDiskGetCacheableBlockCount(IN ULONG DriveNumber)
     return FALSE;
 }
 
-BOOLEAN
-ArmDiskGetBootVolume(IN PULONG DriveNumber,
-                     IN PULONGLONG StartSector,
-                     IN PULONGLONG SectorCount, 
-                     OUT PINT FsType)
+VOID
+ArmPrepareForReactOS(IN BOOLEAN Setup)
 {
+    while (TRUE);
+}
+
+PCONFIGURATION_COMPONENT_DATA
+ArmHwDetect(VOID)
+{
+    PCONFIGURATION_COMPONENT_DATA RootNode;
+    
     //
-    // We only support RAM disk for now -- add support for NAND later
+    // Create the root node
     //
-    ASSERT(gRamDiskBase);
-    ASSERT(gRamDiskSize);
-
+    FldrCreateSystemKey(&RootNode);
+    
     //
-    // Use magic ramdisk drive number and count the number of 512-byte sectors
+    // Write null component information
     //
-    *DriveNumber = 0x49;
-    *StartSector = 63;
-    *SectorCount = gRamDiskSize * 512;
-
+    FldrSetComponentInformation(RootNode,
+                                0x0,
+                                0x0,
+                                0xFFFFFFFF);
+    
     //
-    // Ramdisk support is FAT-only for now
+    // TODO:
+    // There's no such thing as "PnP" on embedded hardware.
+    // The boot loader will send us a device tree, similar to ACPI
+    // or OpenFirmware device trees, and we will convert it to ARC.
     //
-    *FsType = FS_FAT;
 
     //
-    // Now that ramdisk is enabled, use ramdisk routines
+    // Return the root node
     //
-    RamDiskSwitchFromBios();
-    return TRUE;
-}
-
-BOOLEAN
-ArmDiskGetSystemVolume(IN PCHAR SystemPath,
-                       OUT PCHAR RemainingPath,
-                       OUT PULONG Device,
-                       OUT PULONG DriveNumber,
-                       OUT PULONGLONG StartSector,
-                       OUT PULONGLONG SectorCount,
-                       OUT PINT FsType)
-{
-    while (TRUE);
-    return FALSE;
-}
-
-BOOLEAN
-ArmDiskNormalizeSystemPath(IN PCHAR SystemPath,
-                           IN unsigned Size)
-{
-    while (TRUE);
-    return FALSE;
-}
-
-VOID
-ArmPrepareForReactOS(IN BOOLEAN Setup)
-{
-    while (TRUE);
-}
-
-PCONFIGURATION_COMPONENT_DATA
-ArmHwDetect(VOID)
-{
-    while (TRUE);
-    return NULL;
+    return RootNode;
 }
 
 ULONG
@@ -155,18 +126,31 @@ MachInit(IN PCCH CommandLine)
     }
     
     //
-    // Setup generic ARM routines
+    // Setup generic ARM routines for all boards
     //
     MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
     MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
-    MachVtbl.DiskGetBootVolume = ArmDiskGetBootVolume;
-    MachVtbl.DiskGetSystemVolume = ArmDiskGetSystemVolume;
-    MachVtbl.DiskNormalizeSystemPath = ArmDiskNormalizeSystemPath;
+    MachVtbl.HwDetect = ArmHwDetect;
+
+    //
+    // Setup disk I/O routines, switch to ramdisk ones for non-NAND boot
+    //
     MachVtbl.DiskReadLogicalSectors = ArmDiskReadLogicalSectors;
     MachVtbl.DiskGetDriveGeometry = ArmDiskGetDriveGeometry;
     MachVtbl.DiskGetCacheableBlockCount = ArmDiskGetCacheableBlockCount;
-    MachVtbl.HwDetect = ArmHwDetect;
-    
+    RamDiskSwitchFromBios();
+
+    //
+    // Now set default disk handling routines -- we don't need to override
+    //
+    MachVtbl.DiskGetBootVolume = DiskGetBootVolume;
+    MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume;
+    MachVtbl.DiskGetBootPath = DiskGetBootPath;
+    MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
+    MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy;
+    MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
+    MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry;
+
     //
     // We can now print to the console
     //
index 66e9f5c..24c899a 100644 (file)
@@ -46,16 +46,16 @@ EXTERN(RealEntryPoint)
 
        .code32
 
-       /* Zero i386BootDrive and i386BootPartition */
+       /* Zero BootDrive and BootPartition */
        xorl    %eax,%eax
-       movl    %eax,(_i386BootDrive)
-       movl    %eax,(_i386BootPartition)
+       movl    %eax,(_BootDrive)
+       movl    %eax,(_BootPartition)
 
        /* Store the boot drive */
-       movb    %dl,(_i386BootDrive)
+       movb    %dl,(_BootDrive)
 
        /* Store the boot partition */
-       movb    %dh,(_i386BootPartition)
+       movb    %dh,(_BootPartition)
 
        /* GO! */
        pushl   %eax
@@ -395,12 +395,12 @@ mb4:
        movl    MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax
        shrl    $16,%eax
        incb    %al
-       movb    %al,_i386BootPartition
-       movb    %ah,_i386BootDrive
+       movb    %al,_BootPartition
+       movb    %ah,_BootDrive
        jmp     mb6
 mb5:   /* No boot device known, assume first partition of first harddisk */
-       movb    $0x80,_i386BootDrive
-       movb    $1,_i386BootPartition
+       movb    $0x80,_BootDrive
+       movb    $1,_BootPartition
 mb6:
        /* Check for command line */
        mov     $cmdline,%eax
@@ -484,14 +484,14 @@ rmode_idtptr:
        .word   0x3ff           /* Limit */
        .long   0                       /* Base Address */
 
-EXTERN(_i386BootDrive)
-       .long   0
-
-EXTERN(_i386BootPartition)
-       .long   0
-
 mb_info:
        .fill   MB_INFO_SIZE, 1, 0
 
 cmdline:
        .fill   CMDLINE_SIZE, 1, 0
+
+EXTERN(_BootDrive)
+    .long 0
+    
+EXTERN(_BootPartition)
+    .long 0
index 3fb9bbb..ef46585 100644 (file)
@@ -31,7 +31,7 @@ EXTERN(_ChainLoadBiosBootSectorCode)
        .code16
 
        /* Set the boot drive */
-       movb    (_i386BootDrive),%dl
+       movb    (_BootDrive),%dl
 
        /* Load segment registers */
        cli
index 20d7c69..a312256 100644 (file)
@@ -198,309 +198,6 @@ BOOLEAN DiskGetExtendedDriveParameters(ULONG DriveNumber, PVOID Buffer, USHORT B
        return TRUE;
 }
 
-BOOLEAN i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
-{
-       PARTITION_TABLE_ENTRY   PartitionTableEntry;
-       UCHAR                   VolumeType;
-       ULONG                   ActivePartition;
-
-       DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", i386BootDrive, i386BootPartition));
-
-       // Check and see if it is a floppy drive
-       // If so then just assume FAT12 file system type
-       if (DiskIsDriveRemovable(i386BootDrive))
-       {
-               DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
-
-               *DriveNumber = i386BootDrive;
-               *StartSector = 0;
-               *SectorCount = 2 * 80 * 18; /* FIXME hardcoded for 1.44 Mb */
-               *FsType = FS_FAT;
-               return TRUE;
-       }
-
-       // Check for ISO9660 file system type
-       if (i386BootDrive >= 0x80 && FsRecIsIso9660(i386BootDrive))
-       {
-               DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
-
-               *DriveNumber = i386BootDrive;
-               *StartSector = 0;
-               *SectorCount = 0;
-               *FsType = FS_ISO9660;
-               return TRUE;
-       }
-
-       // Get the requested partition entry
-       if (i386BootPartition == 0)
-       {
-               // Partition requested was zero which means the boot partition
-               if (! DiskGetActivePartitionEntry(i386BootDrive, &PartitionTableEntry, &ActivePartition))
-               {
-                       /* Try partition-less disk */
-                       *StartSector = 0;
-                       *SectorCount = 0;
-               }
-               /* Check for valid partition */
-               else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
-               {
-                       return FALSE;
-               }
-               else
-               {
-                       *StartSector = PartitionTableEntry.SectorCountBeforePartition;
-                       *SectorCount = PartitionTableEntry.PartitionSectorCount;
-               }
-       }
-       else if (0xff == i386BootPartition)
-       {
-               /* Partition-less disk */
-               *StartSector = 0;
-               *SectorCount = 0;
-       }
-       else
-       {
-               // Get requested partition
-               if (! MachDiskGetPartitionEntry(i386BootDrive, i386BootPartition, &PartitionTableEntry))
-               {
-                       return FALSE;
-               }
-               /* Check for valid partition */
-               else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
-               {
-                       return FALSE;
-               }
-               else
-               {
-                       *StartSector = PartitionTableEntry.SectorCountBeforePartition;
-                       *SectorCount = PartitionTableEntry.PartitionSectorCount;
-               }
-       }
-
-       // Try to recognize the file system
-       if (!FsRecognizeVolume(i386BootDrive, *StartSector, &VolumeType))
-       {
-               return FALSE;
-       }
-
-       *DriveNumber = i386BootDrive;
-
-       switch (VolumeType)
-       {
-       case PARTITION_FAT_12:
-       case PARTITION_FAT_16:
-       case PARTITION_HUGE:
-       case PARTITION_XINT13:
-       case PARTITION_FAT32:
-       case PARTITION_FAT32_XINT13:
-               *FsType = FS_FAT;
-               return TRUE;
-       case PARTITION_EXT2:
-               *FsType = FS_EXT2;
-               return TRUE;
-       case PARTITION_NTFS:
-               *FsType = FS_NTFS;
-               return TRUE;
-       default:
-               *FsType = 0;
-               return FALSE;
-       }
-
-       return TRUE;
-}
-
-VOID
-i386DiskGetBootDevice(PULONG BootDevice)
-{
-  ((char *)BootDevice)[0] = (char)i386BootDrive;
-  ((char *)BootDevice)[1] = (char)i386BootPartition;
-}
-
-BOOLEAN
-i386DiskBootingFromFloppy(VOID)
-{
-  return i386BootDrive < 0x80;
-}
-
-#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)
-
-#define IsContainerPartition(P) \
-    ((P) == PARTITION_EXTENDED         || \
-     (P) == PARTITION_XINT13_EXTENDED)
-
-BOOLEAN i386DiskGetSystemVolume(char *SystemPath,
-                             char *RemainingPath,
-                             PULONG Device,
-                             PULONG DriveNumber,
-                             PULONGLONG StartSector,
-                             PULONGLONG SectorCount,
-                             int *FsType)
-{
-       ULONG PartitionNumber;
-       PARTITION_TABLE_ENTRY PartitionTableEntry;
-       UCHAR VolumeType;
-       CHAR BootPath[256];
-       unsigned i, RosPartition;
-
-       /*
-        * Verify system path
-        */
-       if (!DissectArcPath(SystemPath, BootPath, DriveNumber, &PartitionNumber))
-       {
-               return FALSE;
-       }
-       if (NULL != RemainingPath)
-       {
-               strcpy(RemainingPath, BootPath);
-       }
-
-       /* 0xff -> no partition table present, use whole device */
-       if (0xff == PartitionNumber)
-       {
-               PartitionTableEntry.SectorCountBeforePartition = 0;
-               i = 0xff;
-       }
-       else
-       {
-               /* recalculate the boot partition for freeldr */
-               i = 0;
-               RosPartition = 0;
-               while (1)
-               {
-                       if (!MachDiskGetPartitionEntry(*DriveNumber, ++i, &PartitionTableEntry))
-                       {
-                               return FALSE;
-                       }
-                        if (!IsContainerPartition(PartitionTableEntry.SystemIndicator) &&
-                            PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
-                       {
-                               if (++RosPartition == PartitionNumber)
-                               {
-                                       break;
-                               }
-                       }
-               }
-       }
-
-       /* Check for ISO9660 file system type */
-       if (*DriveNumber >= 0x80 && FsRecIsIso9660(*DriveNumber))
-       {
-               DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
-
-               if (NULL != Device)
-               {
-                       ((char *)Device)[0] = (char)(*DriveNumber);
-                       ((char *)Device)[1] = (char)i;
-               }
-               *StartSector = 0;
-               *SectorCount = 0;
-               *FsType = FS_ISO9660;
-               return TRUE;
-       }
-
-       if (!FsRecognizeVolume(*DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
-       {
-               return FALSE;
-       }
-
-       if (NULL != Device)
-       {
-               ((char *)Device)[0] = (char)(*DriveNumber);
-               ((char *)Device)[1] = (char)i;
-       }
-       *StartSector = PartitionTableEntry.SectorCountBeforePartition;
-       *SectorCount = PartitionTableEntry.PartitionSectorCount;
-
-       switch (VolumeType)
-       {
-       case PARTITION_FAT_12:
-       case PARTITION_FAT_16:
-       case PARTITION_HUGE:
-       case PARTITION_XINT13:
-       case PARTITION_FAT32:
-       case PARTITION_FAT32_XINT13:
-               *FsType = FS_FAT;
-               return TRUE;
-       case PARTITION_EXT2:
-               *FsType = FS_EXT2;
-               return TRUE;
-       case PARTITION_NTFS:
-               *FsType = FS_NTFS;
-               return TRUE;
-       default:
-               *FsType = 0;
-               return FALSE;
-       }
-
-       return FALSE;
-}
-
-BOOLEAN
-i386DiskGetBootPath(char *BootPath, unsigned Size)
-{
-       static char Path[] = "multi(0)disk(0)";
-       char Device[4];
-
-       _itoa(i386BootDrive, Device, 10);
-       if (Size <= sizeof(Path) + 6 + strlen(Device))
-       {
-               return FALSE;
-       }
-       strcpy(BootPath, Path);
-       strcat(BootPath, MachDiskBootingFromFloppy() ? "fdisk" : "cdrom");
-       strcat(strcat(strcat(BootPath, "("), Device), ")");
-
-       return TRUE;
-}
-
-BOOLEAN
-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 */
index 43c1c20..16a5a00 100644 (file)
@@ -30,7 +30,7 @@ EXTERN(_BootNewLinuxKernel)
        .code16
 
        /* Set the boot drive */
-       movb    (_i386BootDrive),%dl
+       movb    (_BootDrive),%dl
 
        /* Load segment registers */
        cli
@@ -66,7 +66,7 @@ EXTERN(_BootOldLinuxKernel)
        .code16
 
        /* Set the boot drive */
-       movb    (_i386BootDrive),%dl
+       movb    (_BootDrive),%dl
 
        /* Load segment registers */
        cli
index 98fbb61..f9e8734 100644 (file)
@@ -44,14 +44,14 @@ PcMachInit(const char *CmdLine)
     MachVtbl.Beep = PcBeep;
     MachVtbl.PrepareForReactOS = PcPrepareForReactOS;
     MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
-    MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume;
-    MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume;
-    MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
-    MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
-    MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
-    MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
+    MachVtbl.DiskGetBootVolume = DiskGetBootVolume;
+    MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume;
+    MachVtbl.DiskGetBootPath = DiskGetBootPath;
+    MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
+    MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy;
+    MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
     MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
-    MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry;
+    MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry;
     MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
     MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount;
     MachVtbl.RTCGetCurrentDateTime = PcRTCGetCurrentDateTime;
index ff13a59..e09a6d2 100644 (file)
@@ -47,12 +47,12 @@ XboxMachInit(const char *CmdLine)
   MachVtbl.Beep = PcBeep;
   MachVtbl.PrepareForReactOS = XboxPrepareForReactOS;
   MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
-  MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume;
-  MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume;
-  MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
-  MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
-  MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
-  MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
+  MachVtbl.DiskGetBootVolume = DiskGetBootVolume;
+  MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume;
+  MachVtbl.DiskGetBootPath = DiskGetBootPath;
+  MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
+  MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy;
+  MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
   MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
   MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry;
   MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
index 568b897..5d3d917 100644 (file)
@@ -378,13 +378,6 @@ BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULON
        return TRUE;
 }
 
-BOOLEAN
-PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
-{
-  /* Just use the standard routine */
-  return DiskGetPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
-}
-
 BOOLEAN
 PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry)
 {
index d01dce3..14b738f 100644 (file)
@@ -91,7 +91,8 @@ BOOLEAN DiskIsDriveRemovable(ULONG DriveNumber)
        // Hard disks use drive numbers >= 0x80
        // So if the drive number indicates a hard disk
        // then return FALSE
-       if (DriveNumber >= 0x80)
+    // 0x49 is our magic ramdisk drive, so return FALSE for that too
+       if ((DriveNumber >= 0x80) || (DriveNumber == 0x49))
        {
                return FALSE;
        }
@@ -100,6 +101,310 @@ BOOLEAN DiskIsDriveRemovable(ULONG DriveNumber)
        return TRUE;
 }
 
+BOOLEAN DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
+{
+       PARTITION_TABLE_ENTRY   PartitionTableEntry;
+       UCHAR                   VolumeType;
+       ULONG                   ActivePartition;
+    
+       DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", BootDrive, BootPartition));
+    
+       // Check and see if it is a floppy drive
+       // If so then just assume FAT12 file system type
+       if (DiskIsDriveRemovable(BootDrive))
+       {
+               DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
+        
+               *DriveNumber = BootDrive;
+               *StartSector = 0;
+               *SectorCount = 2 * 80 * 18; /* FIXME hardcoded for 1.44 Mb */
+               *FsType = FS_FAT;
+               return TRUE;
+       }
+    
+       // Check for ISO9660 file system type
+       if (BootDrive >= 0x80 && FsRecIsIso9660(BootDrive))
+       {
+               DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
+        
+               *DriveNumber = BootDrive;
+               *StartSector = 0;
+               *SectorCount = 0;
+               *FsType = FS_ISO9660;
+               return TRUE;
+       }
+    
+       // Get the requested partition entry
+       if (BootPartition == 0)
+       {
+               // Partition requested was zero which means the boot partition
+               if (! DiskGetActivePartitionEntry(BootDrive, &PartitionTableEntry, &ActivePartition))
+               {
+                       /* Try partition-less disk */
+                       *StartSector = 0;
+                       *SectorCount = 0;
+               }
+               /* Check for valid partition */
+               else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
+               {
+                       return FALSE;
+               }
+               else
+               {
+                       *StartSector = PartitionTableEntry.SectorCountBeforePartition;
+                       *SectorCount = PartitionTableEntry.PartitionSectorCount;
+               }
+       }
+       else if (0xff == BootPartition)
+       {
+               /* Partition-less disk */
+               *StartSector = 0;
+               *SectorCount = 0;
+       }
+       else
+       {
+               // Get requested partition
+               if (! MachDiskGetPartitionEntry(BootDrive, BootPartition, &PartitionTableEntry))
+               {
+                       return FALSE;
+               }
+               /* Check for valid partition */
+               else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
+               {
+                       return FALSE;
+               }
+               else
+               {
+                       *StartSector = PartitionTableEntry.SectorCountBeforePartition;
+                       *SectorCount = PartitionTableEntry.PartitionSectorCount;
+               }
+       }
+    
+       // Try to recognize the file system
+       if (!FsRecognizeVolume(BootDrive, *StartSector, &VolumeType))
+       {
+               return FALSE;
+       }
+    
+       *DriveNumber = BootDrive;
+    
+       switch (VolumeType)
+       {
+        case PARTITION_FAT_12:
+        case PARTITION_FAT_16:
+        case PARTITION_HUGE:
+        case PARTITION_XINT13:
+        case PARTITION_FAT32:
+        case PARTITION_FAT32_XINT13:
+            *FsType = FS_FAT;
+            return TRUE;
+        case PARTITION_EXT2:
+            *FsType = FS_EXT2;
+            return TRUE;
+        case PARTITION_NTFS:
+            *FsType = FS_NTFS;
+            return TRUE;
+        default:
+            *FsType = 0;
+            return FALSE;
+       }
+    
+       return TRUE;
+}
+
+VOID
+DiskGetBootDevice(PULONG BootDevice)
+{
+    ((char *)BootDevice)[0] = (char)BootDrive;
+    ((char *)BootDevice)[1] = (char)BootPartition;
+}
+
+BOOLEAN
+DiskBootingFromFloppy(VOID)
+{
+    return BootDrive < 0x80;
+}
+
+#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)
+
+#define IsContainerPartition(P) \
+    ((P) == PARTITION_EXTENDED         || \
+     (P) == PARTITION_XINT13_EXTENDED)
+
+BOOLEAN DiskGetSystemVolume(char *SystemPath,
+                            char *RemainingPath,
+                            PULONG Device,
+                            PULONG DriveNumber,
+                            PULONGLONG StartSector,
+                            PULONGLONG SectorCount,
+                            int *FsType)
+{
+       ULONG PartitionNumber;
+       PARTITION_TABLE_ENTRY PartitionTableEntry;
+       UCHAR VolumeType;
+       CHAR BootPath[256];
+       unsigned i, RosPartition;
+    
+       /*
+        * Verify system path
+        */
+       if (!DissectArcPath(SystemPath, BootPath, DriveNumber, &PartitionNumber))
+       {
+               return FALSE;
+       }
+       if (NULL != RemainingPath)
+       {
+               strcpy(RemainingPath, BootPath);
+       }
+    
+       /* 0xff -> no partition table present, use whole device */
+       if (0xff == PartitionNumber)
+       {
+               PartitionTableEntry.SectorCountBeforePartition = 0;
+               i = 0xff;
+       }
+       else
+       {
+               /* recalculate the boot partition for freeldr */
+               i = 0;
+               RosPartition = 0;
+               while (1)
+               {
+                       if (!MachDiskGetPartitionEntry(*DriveNumber, ++i, &PartitionTableEntry))
+                       {
+                               return FALSE;
+                       }
+            if (!IsContainerPartition(PartitionTableEntry.SystemIndicator) &&
+                PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
+                       {
+                               if (++RosPartition == PartitionNumber)
+                               {
+                                       break;
+                               }
+                       }
+               }
+       }
+    
+       /* Check for ISO9660 file system type */
+       if (*DriveNumber >= 0x80 && FsRecIsIso9660(*DriveNumber))
+       {
+               DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
+        
+               if (NULL != Device)
+               {
+                       ((char *)Device)[0] = (char)(*DriveNumber);
+                       ((char *)Device)[1] = (char)i;
+               }
+               *StartSector = 0;
+               *SectorCount = 0;
+               *FsType = FS_ISO9660;
+               return TRUE;
+       }
+    
+       if (!FsRecognizeVolume(*DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
+       {
+               return FALSE;
+       }
+    
+       if (NULL != Device)
+       {
+               ((char *)Device)[0] = (char)(*DriveNumber);
+               ((char *)Device)[1] = (char)i;
+       }
+       *StartSector = PartitionTableEntry.SectorCountBeforePartition;
+       *SectorCount = PartitionTableEntry.PartitionSectorCount;
+    
+       switch (VolumeType)
+       {
+        case PARTITION_FAT_12:
+        case PARTITION_FAT_16:
+        case PARTITION_HUGE:
+        case PARTITION_XINT13:
+        case PARTITION_FAT32:
+        case PARTITION_FAT32_XINT13:
+            *FsType = FS_FAT;
+            return TRUE;
+        case PARTITION_EXT2:
+            *FsType = FS_EXT2;
+            return TRUE;
+        case PARTITION_NTFS:
+            *FsType = FS_NTFS;
+            return TRUE;
+        default:
+            *FsType = 0;
+            return FALSE;
+       }
+    
+       return FALSE;
+}
+
+BOOLEAN
+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, MachDiskBootingFromFloppy() ? "fdisk" : "cdrom");
+       strcat(strcat(strcat(BootPath, "("), Device), ")");
+    
+       return TRUE;
+}
+
+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))
+       {
+               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;
+}
+
+
 // This function is in arch/i386/i386disk.c
 //VOID DiskStopFloppyMotor(VOID)
 
index 3dddb5a..b31a1aa 100644 (file)
@@ -38,6 +38,7 @@ RamDiskGetCacheableBlockCount(IN ULONG Reserved)
     //
     // Allow 32KB transfers (64 sectors), emulating BIOS LBA
     //
+    ASSERT(Reserved == 0x49);
     return 64;
 }
 
@@ -48,6 +49,7 @@ RamDiskGetDriveGeometry(IN ULONG Reserved,
     //
     // Should never be called when the caller expects valid Geometry!
     //
+    ASSERT(Reserved == 0x49);
     return TRUE;
 }
 
@@ -59,7 +61,8 @@ RamDiskReadLogicalSectors(IN ULONG Reserved,
 {
     PVOID StartAddress;
     ULONG Length;
-        
+    ASSERT(Reserved == 0x49);
+
     //
     // Get actual pointers and lengths
     //
@@ -145,6 +148,8 @@ VOID
 NTAPI
 RamDiskSwitchFromBios(VOID)
 {
+    extern ULONG BootDrive, BootPartition;
+
     //
     // Check if we have a ramdisk, in which case we need to switch routines
     //
@@ -161,5 +166,11 @@ RamDiskSwitchFromBios(VOID)
         // Also disable cached FAT reads
         //
         gCacheEnabled = FALSE;
+        
+        //
+        // Switch to ramdisk boot partition
+        //
+        BootDrive = 0x49;
+        BootPartition = 0;
     }
 }
index ec4106b..dd904ba 100644 (file)
 #define __I386_I386_H_
 
 
-extern ULONG i386BootDrive;
-extern ULONG i386BootPartition;
-
-extern BOOLEAN i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector,
-                                  PULONGLONG SectorCount, int *FsType);
-extern BOOLEAN i386DiskGetSystemVolume(char *SystemPath, char *RemainingPath,
-                                    PULONG Device, PULONG DriveNumber,
-                                    PULONGLONG StartSector,
-                                    PULONGLONG SectorCount, int *FsType);
-extern BOOLEAN i386DiskGetBootPath(char *BootPath, unsigned Size);
-extern VOID i386DiskGetBootDevice(PULONG BootDevice);
-extern BOOLEAN i386DiskBootingFromFloppy(VOID);
-extern BOOLEAN i386DiskNormalizeSystemPath(char *SystemPath, unsigned Size);
 
 #endif /* __I386_I386_H_ */
 
index 7aa01e4..c4e4caa 100644 (file)
@@ -124,6 +124,20 @@ PCSTR      DiskGetErrorCodeString(ULONG ErrorCode);
 BOOLEAN        DiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); // Implemented in i386disk.c
 BOOLEAN        DiskIsDriveRemovable(ULONG DriveNumber);
 VOID   DiskStopFloppyMotor(VOID);      // Implemented in i386disk.c
+extern ULONG BootDrive;
+extern ULONG BootPartition;
+
+BOOLEAN DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector,
+                          PULONGLONG SectorCount, int *FsType);
+BOOLEAN DiskGetSystemVolume(char *SystemPath, char *RemainingPath,
+                            PULONG Device, PULONG DriveNumber,
+                            PULONGLONG StartSector,
+                            PULONGLONG SectorCount, int *FsType);
+BOOLEAN DiskGetBootPath(char *BootPath, unsigned Size);
+VOID DiskGetBootDevice(PULONG BootDevice);
+BOOLEAN DiskBootingFromFloppy(VOID);
+BOOLEAN DiskNormalizeSystemPath(char *SystemPath, unsigned Size);
+
 
 ///////////////////////////////////////////////////////////////////////////////////////
 //