[freeldr] Remove (Mach)DiskGetBootDevice, DiskGetBootVolume, DiskGetSystemVolume, FsRecognizeVolume

This commit breaks ext2 driver in freeldr, which needs to use ArcSeek/ArcRead/Arc* instead of DiskGetBootVolume/MachDiskReadLogicalSectors

svn path=/trunk/; revision=43268
This commit is contained in:
Hervé Poussineau 2009-10-03 17:00:29 +00:00
parent c599bd7dc0
commit f501c2bcb5
14 changed files with 14 additions and 418 deletions

View file

@ -202,7 +202,6 @@ MachInit(IN PCCH CommandLine)
// Now set default disk handling routines -- we don't need to override
//
MachVtbl.DiskGetBootPath = DiskGetBootPath;
MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry;

View file

@ -45,7 +45,6 @@ PcMachInit(const char *CmdLine)
MachVtbl.PrepareForReactOS = PcPrepareForReactOS;
MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
MachVtbl.DiskGetBootPath = DiskGetBootPath;
MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry;

View file

@ -48,7 +48,6 @@ XboxMachInit(const char *CmdLine)
MachVtbl.PrepareForReactOS = XboxPrepareForReactOS;
MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
MachVtbl.DiskGetBootPath = DiskGetBootPath;
MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry;

View file

@ -252,10 +252,6 @@ BOOLEAN PpcDiskGetBootPath( char *OutBootPath, unsigned Size ) {
return TRUE;
}
VOID PpcDiskGetBootDevice( PULONG BootDevice ) {
BootDevice[0] = BootDevice[1] = 0;
}
BOOLEAN PpcDiskReadLogicalSectors( ULONG DriveNumber, ULONGLONG SectorNumber,
ULONG SectorCount, PVOID Buffer ) {
int rlen = 0;
@ -490,7 +486,6 @@ void PpcDefaultMachVtbl()
MachVtbl.DiskNormalizeSystemPath = PpcDiskNormalizeSystemPath;
MachVtbl.DiskGetBootPath = PpcDiskGetBootPath;
MachVtbl.DiskGetBootDevice = PpcDiskGetBootDevice;
MachVtbl.DiskReadLogicalSectors = PpcDiskReadLogicalSectors;
MachVtbl.DiskGetPartitionEntry = PpcDiskGetPartitionEntry;
MachVtbl.DiskGetDriveGeometry = PpcDiskGetDriveGeometry;

View file

@ -101,231 +101,6 @@ BOOLEAN DiskIsDriveRemovable(ULONG DriveNumber)
return TRUE;
}
BOOLEAN DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
{
PARTITION_TABLE_ENTRY PartitionTableEntry;
UCHAR VolumeType;
ULONG ActivePartition;
DPRINTM(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))
{
DPRINTM(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))
{
DPRINTM(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;
}
#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)
{
ULONG PartitionNumber;
PARTITION_TABLE_ENTRY PartitionTableEntry;
UCHAR VolumeType;
CHAR BootPath[256];
unsigned i, RosPartition;
ULONG DriveNumber;
/*
* 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))
{
DPRINTM(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;
}
return TRUE;
}
if (!FsRecognizeVolume(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
{
return FALSE;
}
if (NULL != Device)
{
((char *)Device)[0] = (char)DriveNumber;
((char *)Device)[1] = (char)i;
}
switch (VolumeType)
{
case PARTITION_FAT_12:
case PARTITION_FAT_16:
case PARTITION_HUGE:
case PARTITION_XINT13:
case PARTITION_FAT32:
case PARTITION_FAT32_XINT13:
case PARTITION_EXT2:
case PARTITION_NTFS:
return TRUE;
default:
return FALSE;
}
return FALSE;
}
BOOLEAN
DiskGetBootPath(char *BootPath, unsigned Size)
{

View file

@ -31,7 +31,6 @@
<file>ext2.c</file>
<file>fat.c</file>
<file>fs.c</file>
<file>fsrec.c</file>
<file>iso.c</file>
<file>ntfs.c</file>
</directory>

View file

@ -60,6 +60,15 @@ ULONG Ext2GroupCount = 0; // Number of groups in this file system
ULONG Ext2InodesPerBlock = 0; // Number of inodes in one block
ULONG Ext2GroupDescPerBlock = 0; // Number of group descriptors in one block
BOOLEAN DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
{
*DriveNumber = 0;
*StartSector = 0;
*SectorCount = 0;
*FsType = 0;
return FALSE;
}
BOOLEAN Ext2OpenVolume(UCHAR DriveNumber, ULONGLONG VolumeStartSector, ULONGLONG PartitionSectorCount)
{

View file

@ -1,131 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#define NDEBUG
#include <debug.h>
/////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////////
/*
*
* BOOLEAN FsRecognizeVolume(ULONG DriveNumber, ULONG VolumeStartSector, UCHAR* VolumeType);
*
*/
BOOLEAN FsRecognizeVolume(ULONG DriveNumber, ULONG VolumeStartSector, UCHAR* VolumeType)
{
DPRINTM(DPRINT_FILESYSTEM, "FsRecognizeVolume() DriveNumber: 0x%x VolumeStartSector: %d\n", DriveNumber, VolumeStartSector);
if (FsRecIsFat(DriveNumber, VolumeStartSector))
{
*VolumeType = PARTITION_FAT32;
return TRUE;
}
else if (FsRecIsNtfs(DriveNumber, VolumeStartSector))
{
*VolumeType = PARTITION_NTFS;
return TRUE;
}
else if (FsRecIsExt2(DriveNumber, VolumeStartSector))
{
*VolumeType = PARTITION_EXT2;
return TRUE;
}
return FALSE;
}
BOOLEAN FsRecIsIso9660(ULONG DriveNumber)
{
PUCHAR Sector = (PUCHAR)DISKREADBUFFER;
if (!MachDiskReadLogicalSectors(DriveNumber, 16, 1, Sector))
{
FileSystemError("Failed to read the PVD.");
return FALSE;
}
return (Sector[0] == 1 &&
Sector[1] == 'C' &&
Sector[2] == 'D' &&
Sector[3] == '0' &&
Sector[4] == '0' &&
Sector[5] == '1');
}
BOOLEAN FsRecIsExt2(ULONG DriveNumber, ULONG VolumeStartSector)
{
PEXT2_SUPER_BLOCK SuperBlock = (PEXT2_SUPER_BLOCK)DISKREADBUFFER;
if (!MachDiskReadLogicalSectors(DriveNumber, VolumeStartSector + 2, 2, SuperBlock))
{
FileSystemError("Failed to read the super block.");
return FALSE;
}
if (SuperBlock->magic == EXT2_MAGIC)
{
return TRUE;
}
return FALSE;
}
BOOLEAN FsRecIsFat(ULONG DriveNumber, ULONG VolumeStartSector)
{
PFAT_BOOTSECTOR BootSector = (PFAT_BOOTSECTOR)DISKREADBUFFER;
PFAT32_BOOTSECTOR BootSector32 = (PFAT32_BOOTSECTOR)DISKREADBUFFER;
PFATX_BOOTSECTOR BootSectorX = (PFATX_BOOTSECTOR)DISKREADBUFFER;
if (!MachDiskReadLogicalSectors(DriveNumber, VolumeStartSector, 1, BootSector))
{
FileSystemError("Failed to read the boot sector.");
return FALSE;
}
if (strncmp(BootSector->FileSystemType, "FAT12 ", 8) == 0 ||
strncmp(BootSector->FileSystemType, "FAT16 ", 8) == 0 ||
strncmp(BootSector32->FileSystemType, "FAT32 ", 8) == 0 ||
strncmp(BootSectorX->FileSystemType, "FATX", 4) == 0)
{
return TRUE;
}
return FALSE;
}
BOOLEAN FsRecIsNtfs(ULONG DriveNumber, ULONG VolumeStartSector)
{
PNTFS_BOOTSECTOR BootSector = (PNTFS_BOOTSECTOR)DISKREADBUFFER;
if (!MachDiskReadLogicalSectors(DriveNumber, VolumeStartSector, 1, BootSector))
{
FileSystemError("Failed to read the boot sector.");
return FALSE;
}
if (RtlEqualMemory(BootSector->SystemId, "NTFS", 4))
{
return TRUE;
}
return FALSE;
}

View file

@ -127,12 +127,7 @@ 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);
BOOLEAN DiskGetBootPath(char *BootPath, unsigned Size);
VOID DiskGetBootDevice(PULONG BootDevice);
BOOLEAN DiskNormalizeSystemPath(char *SystemPath, unsigned Size);

View file

@ -59,7 +59,6 @@
#include <reactos.h>
#include <registry.h>
#include <winldr.h>
#include <fsrec.h>
/* file system headers */
#include <fs/ext2.h>
#include <fs/fat.h>

View file

@ -1,29 +0,0 @@
/*
* FreeLoader
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __FSREC_H
#define __FSREC_H
BOOLEAN FsRecognizeVolume(ULONG DriveNumber, ULONG VolumeStartSector, UCHAR* VolumeType);
BOOLEAN FsRecIsIso9660(ULONG DriveNumber);
BOOLEAN FsRecIsExt2(ULONG DriveNumber, ULONG VolumeStartSector);
BOOLEAN FsRecIsFat(ULONG DriveNumber, ULONG VolumeStartSector);
BOOLEAN FsRecIsNtfs(ULONG DriveNumber, ULONG VolumeStartSector);
#endif // #defined __FSREC_H

View file

@ -63,7 +63,6 @@ typedef struct tagMACHVTBL
ULONG (*GetMemoryMap)(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize);
BOOLEAN (*DiskGetBootPath)(char *BootPath, unsigned Size);
VOID (*DiskGetBootDevice)(PULONG BootDevice);
BOOLEAN (*DiskNormalizeSystemPath)(char *SystemPath, unsigned Size);
BOOLEAN (*DiskReadLogicalSectors)(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOLEAN (*DiskGetPartitionEntry)(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
@ -98,7 +97,6 @@ VOID MachVideoSync(VOID);
VOID MachBeep(VOID);
MEMORY_DESCRIPTOR* ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current);
BOOLEAN MachDiskGetBootPath(char *BootPath, unsigned Size);
VOID MachDiskGetBootDevice(PULONG BootDevice);
BOOLEAN MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size);
BOOLEAN MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOLEAN MachDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
@ -127,7 +125,6 @@ VOID MachPrepareForReactOS(IN BOOLEAN Setup);
#define MachBeep() MachVtbl.Beep()
#define MachPrepareForReactOS(a) MachVtbl.PrepareForReactOS(a)
#define MachDiskGetBootPath(Path, Size) MachVtbl.DiskGetBootPath((Path), (Size))
#define MachDiskGetBootDevice(BootDevice) MachVtbl.DiskGetBootDevice(BootDevice)
#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))

View file

@ -37,7 +37,6 @@
#undef MachBeep
#undef MachPrepareForReactOS
#undef MachDiskGetBootPath
#undef MachDiskGetBootDevice
#undef MachDiskNormalizeSystemPath
#undef MachDiskReadLogicalSectors
#undef MachDiskGetPartitionEntry
@ -155,12 +154,6 @@ MachDiskGetBootPath(char *BootPath, unsigned Size)
return MachVtbl.DiskGetBootPath(BootPath, Size);
}
VOID
MachDiskGetBootDevice(PULONG BootDevice)
{
MachVtbl.DiskGetBootDevice(BootDevice);
}
BOOLEAN
MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size)
{

View file

@ -755,14 +755,11 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
//
RamDiskSwitchFromBios();
/*
* Try to get system volume
*/
if (!DiskGetSystemVolume(SystemPath, szBootPath, &LoaderBlock.BootDevice))
{
UiMessageBox("Failed to get system volume.");
return;
}
/* Get boot path */
if (strchr(SystemPath, '\\') != NULL)
strcpy(szBootPath, strchr(SystemPath, '\\'));
else
szBootPath[0] = '\0';
/* append a backslash */
if ((strlen(szBootPath)==0) ||