Changes in v1.8.7 (4/22/2003) (brianp)

- Added a file system recognizer to get around problems where
  the partition id did not match the file system type.

svn path=/trunk/; revision=4565
This commit is contained in:
Brian Palmer 2003-04-23 16:47:24 +00:00
parent 198be0032b
commit 201324d607
8 changed files with 165 additions and 25 deletions

View file

@ -1,3 +1,8 @@
Changes in v1.8.7 (4/22/2003) (brianp)
- Added a file system recognizer to get around problems where
the partition id did not match the file system type.
Changes in v1.8.6 (4/14/2003) (brianp)
- Fixed a bug in fathelp.asm where is wasn't adding the hidden sector

View file

@ -219,7 +219,8 @@ RTL_OBJS = print.o \
FS_OBJS = fs.o \
fat.o \
iso.o \
ext2.o
ext2.o \
fsrec.o
UI_OBJS = tui.o \
tuimenu.o \

View file

@ -22,6 +22,7 @@
#include "fat.h"
#include "iso.h"
#include "ext2.h"
#include "fsrec.h"
#include <disk.h>
#include <rtl.h>
#include <ui.h>
@ -65,6 +66,7 @@ BOOL FsOpenVolume(U32 DriveNumber, U32 PartitionNumber)
{
PARTITION_TABLE_ENTRY PartitionTableEntry;
UCHAR ErrorText[80];
U8 VolumeType;
DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", DriveNumber, PartitionNumber));
@ -79,7 +81,7 @@ BOOL FsOpenVolume(U32 DriveNumber, U32 PartitionNumber)
}
// Check for ISO9660 file system type
if (DriveNumber > 0x80 && IsIsoFs(DriveNumber))
if (DriveNumber > 0x80 && FsRecIsIso9660(DriveNumber))
{
DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
@ -117,7 +119,15 @@ BOOL FsOpenVolume(U32 DriveNumber, U32 PartitionNumber)
return FALSE;
}
switch (PartitionTableEntry.SystemIndicator)
// Try to recognize the file system
if (!FsRecognizeVolume(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
{
sprintf(ErrorText, "Unrecognized file system. Type: 0x%x", PartitionTableEntry.SystemIndicator);
FileSystemError(ErrorText);
}
//switch (PartitionTableEntry.SystemIndicator)
switch (VolumeType)
{
case PARTITION_FAT_12:
case PARTITION_FAT_16:

116
freeldr/freeldr/fs/fsrec.c Normal file
View file

@ -0,0 +1,116 @@
/*
* 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>
#include <fs.h>
#include "fsrec.h"
#include "fat.h"
#include "iso.h"
#include "ext2.h"
#include <disk.h>
#include <rtl.h>
#include <arch.h>
#include <debug.h>
/////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////////
/*
*
* BOOL FsRecognizeVolume(U32 DriveNumber, U32 VolumeStartSector, U8* VolumeType);
*
*/
BOOL FsRecognizeVolume(U32 DriveNumber, U32 VolumeStartSector, U8* VolumeType)
{
DbgPrint((DPRINT_FILESYSTEM, "FsRecognizeVolume() DriveNumber: 0x%x VolumeStartSector: %d\n", DriveNumber, VolumeStartSector));
if (FsRecIsExt2(DriveNumber, VolumeStartSector))
{
*VolumeType = PARTITION_EXT2;
return TRUE;
}
else if (FsRecIsFat(DriveNumber, VolumeStartSector))
{
*VolumeType = PARTITION_FAT32;
return TRUE;
}
return FALSE;
}
BOOL FsRecIsIso9660(U32 DriveNumber)
{
PUCHAR Sector = (PUCHAR)DISKREADBUFFER;
if (!DiskReadLogicalSectors(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');
}
BOOL FsRecIsExt2(U32 DriveNumber, U32 VolumeStartSector)
{
PEXT2_SUPER_BLOCK SuperBlock = (PEXT2_SUPER_BLOCK)DISKREADBUFFER;
if (!DiskReadLogicalSectors(DriveNumber, VolumeStartSector + 2, 2, SuperBlock))
{
FileSystemError("Failed to read the super block.");
return FALSE;
}
if (SuperBlock->s_magic == EXT3_SUPER_MAGIC)
{
return TRUE;
}
return FALSE;
}
BOOL FsRecIsFat(U32 DriveNumber, U32 VolumeStartSector)
{
PFAT_BOOTSECTOR BootSector = (PFAT_BOOTSECTOR)DISKREADBUFFER;
if (!DiskReadLogicalSectors(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(BootSector->FileSystemType, "FAT32 ", 8) == 0)
{
return TRUE;
}
return FALSE;
}

View file

@ -0,0 +1,28 @@
/*
* 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
BOOL FsRecognizeVolume(U32 DriveNumber, U32 VolumeStartSector, U8* VolumeType);
BOOL FsRecIsIso9660(U32 DriveNumber);
BOOL FsRecIsExt2(U32 DriveNumber, U32 VolumeStartSector);
BOOL FsRecIsFat(U32 DriveNumber, U32 VolumeStartSector);
#endif // #defined __FSREC_H

View file

@ -37,25 +37,6 @@ static U32 IsoRootLength; // Length of the root directory
U32 IsoDriveNumber = 0;
BOOL IsIsoFs(U32 DriveNumber)
{
PUCHAR Sector = (PUCHAR)DISKREADBUFFER;
if (!DiskReadLogicalSectors(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');
}
BOOL IsoOpenVolume(U32 DriveNumber)
{
PPVD Pvd = (PPVD)DISKREADBUFFER;

View file

@ -105,7 +105,6 @@ typedef struct
} ISO_FILE_INFO, * PISO_FILE_INFO;
BOOL IsIsoFs(U32 DriveNumber);
BOOL IsoOpenVolume(U32 DriveNumber);
FILE* IsoOpenFile(PUCHAR FileName);
BOOL IsoReadFile(FILE *FileHandle, U32 BytesToRead, U32* BytesRead, PVOID Buffer);

View file

@ -22,7 +22,7 @@
/* just some stuff */
#define VERSION "FreeLoader v1.8.6"
#define VERSION "FreeLoader v1.8.7"
#define COPYRIGHT "Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>"
#define AUTHOR_EMAIL "<brianp@sginet.com>"
#define BY_AUTHOR "by Brian Palmer"
@ -36,7 +36,7 @@
//
#define FREELOADER_MAJOR_VERSION 1
#define FREELOADER_MINOR_VERSION 8
#define FREELOADER_PATCH_VERSION 6
#define FREELOADER_PATCH_VERSION 7
PUCHAR GetFreeLoaderVersionString(VOID);