diff --git a/reactos/boot/freeldr/freeldr/arch/arm/stubs.c b/reactos/boot/freeldr/freeldr/arch/arm/stubs.c index 70345a0f796..e8375d033fd 100644 --- a/reactos/boot/freeldr/freeldr/arch/arm/stubs.c +++ b/reactos/boot/freeldr/freeldr/arch/arm/stubs.c @@ -24,7 +24,6 @@ FrLdrStartup(IN ULONG Magic) // } - BOOLEAN ArmDiskGetDriveGeometry(IN ULONG DriveNumber, OUT PGEOMETRY Geometry) @@ -50,58 +49,6 @@ ArmDiskGetCacheableBlockCount(IN ULONG DriveNumber) return FALSE; } -BOOLEAN -ArmDiskGetBootVolume(IN PULONG DriveNumber, - IN PULONGLONG StartSector, - IN PULONGLONG SectorCount, - OUT PINT FsType) -{ - // - // We only support RAM disk for now -- add support for NAND later - // - ASSERT(gRamDiskBase); - ASSERT(gRamDiskSize); - - // - // Use magic ramdisk drive number and count the number of 512-byte sectors - // - *DriveNumber = 0x49; - *StartSector = 63; - *SectorCount = gRamDiskSize * 512; - - // - // Ramdisk support is FAT-only for now - // - *FsType = FS_FAT; - - // - // Now that ramdisk is enabled, use ramdisk routines - // - 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) { @@ -111,8 +58,32 @@ ArmPrepareForReactOS(IN BOOLEAN Setup) PCONFIGURATION_COMPONENT_DATA ArmHwDetect(VOID) { - while (TRUE); - return NULL; + PCONFIGURATION_COMPONENT_DATA RootNode; + + // + // Create the root node + // + FldrCreateSystemKey(&RootNode); + + // + // Write null component information + // + FldrSetComponentInformation(RootNode, + 0x0, + 0x0, + 0xFFFFFFFF); + + // + // 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. + // + + // + // Return the root node + // + 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 // diff --git a/reactos/boot/freeldr/freeldr/arch/i386/arch.S b/reactos/boot/freeldr/freeldr/arch/i386/arch.S index 66e9f5c6b17..24c899a0820 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/arch.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/arch.S @@ -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 diff --git a/reactos/boot/freeldr/freeldr/arch/i386/boot.S b/reactos/boot/freeldr/freeldr/arch/i386/boot.S index 3fb9bbb3a41..ef465851862 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/boot.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/boot.S @@ -31,7 +31,7 @@ EXTERN(_ChainLoadBiosBootSectorCode) .code16 /* Set the boot drive */ - movb (_i386BootDrive),%dl + movb (_BootDrive),%dl /* Load segment registers */ cli diff --git a/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c b/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c index 20d7c697395..a3122564169 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c @@ -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 */ diff --git a/reactos/boot/freeldr/freeldr/arch/i386/linux.S b/reactos/boot/freeldr/freeldr/arch/i386/linux.S index 43c1c201fa2..16a5a001f2d 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/linux.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/linux.S @@ -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 diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c index 98fbb61db4d..f9e87344b05 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c @@ -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; diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c index ff13a5921e4..e09a6d29b53 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c @@ -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; diff --git a/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c b/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c index 568b897cf5f..5d3d917af99 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c @@ -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) { diff --git a/reactos/boot/freeldr/freeldr/disk/disk.c b/reactos/boot/freeldr/freeldr/disk/disk.c index d01dce380e9..14b738fb3bf 100644 --- a/reactos/boot/freeldr/freeldr/disk/disk.c +++ b/reactos/boot/freeldr/freeldr/disk/disk.c @@ -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) diff --git a/reactos/boot/freeldr/freeldr/disk/ramdisk.c b/reactos/boot/freeldr/freeldr/disk/ramdisk.c index 3dddb5a92bf..b31a1aae6f0 100644 --- a/reactos/boot/freeldr/freeldr/disk/ramdisk.c +++ b/reactos/boot/freeldr/freeldr/disk/ramdisk.c @@ -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; } } diff --git a/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h b/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h index ec4106bdbab..dd904baf660 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h +++ b/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h @@ -22,19 +22,6 @@ #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_ */ diff --git a/reactos/boot/freeldr/freeldr/include/disk.h b/reactos/boot/freeldr/freeldr/include/disk.h index 7aa01e4d9bf..c4e4caa1e0c 100644 --- a/reactos/boot/freeldr/freeldr/include/disk.h +++ b/reactos/boot/freeldr/freeldr/include/disk.h @@ -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); + /////////////////////////////////////////////////////////////////////////////////////// //