From 5db0abce79284a01ed51fe2778ef59c982228feb Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Sat, 19 Jan 2002 00:37:06 +0000 Subject: [PATCH] Better LBA support Correctly determines FAT type based on cluster count instead of partition id svn path=/trunk/; revision=2528 --- freeldr/freeldr/Makefile | 2 +- freeldr/freeldr/asmcode.S | 2 +- freeldr/freeldr/asmcode.h | 2 +- freeldr/freeldr/boot.S | 2 +- freeldr/freeldr/cache.h | 2 +- freeldr/freeldr/cache/Makefile | 2 +- freeldr/freeldr/cache/blocklist.c | 2 +- freeldr/freeldr/cache/cache.c | 2 +- freeldr/freeldr/cache/cm.h | 2 +- freeldr/freeldr/comm/Makefile | 2 +- freeldr/freeldr/debug.c | 2 +- freeldr/freeldr/debug.h | 2 +- freeldr/freeldr/disk.h | 2 +- freeldr/freeldr/disk/Makefile | 2 +- freeldr/freeldr/disk/disk.c | 2 +- freeldr/freeldr/disk/geometry.c | 2 +- freeldr/freeldr/freeldr.c | 2 +- freeldr/freeldr/freeldr.h | 6 +- freeldr/freeldr/fs.h | 14 +-- freeldr/freeldr/fs/Makefile | 2 +- freeldr/freeldr/fs/fat.c | 68 +++++++++-- freeldr/freeldr/fs/fat.h | 7 +- freeldr/freeldr/fs/filesys.h | 30 +++++ freeldr/freeldr/fs/fs.c | 179 ++++++++++++++++------------- freeldr/freeldr/linux.c | 2 +- freeldr/freeldr/linux.h | 2 +- freeldr/freeldr/mb.S | 2 +- freeldr/freeldr/mem.S | 2 +- freeldr/freeldr/miscboot.c | 2 +- freeldr/freeldr/miscboot.h | 2 +- freeldr/freeldr/mm.h | 2 +- freeldr/freeldr/mm/Makefile | 2 +- freeldr/freeldr/mm/mm.c | 2 +- freeldr/freeldr/multiboot.c | 2 +- freeldr/freeldr/options.c | 2 +- freeldr/freeldr/options.h | 2 +- freeldr/freeldr/oslist.c | 2 +- freeldr/freeldr/oslist.h | 2 +- freeldr/freeldr/parseini.c | 2 +- freeldr/freeldr/parseini.h | 2 +- freeldr/freeldr/reactos.h | 3 +- freeldr/freeldr/reactos/Makefile | 2 +- freeldr/freeldr/reactos/hwdetect.h | 2 +- freeldr/freeldr/reactos/reactos.c | 2 +- freeldr/freeldr/rtl.h | 2 +- freeldr/freeldr/rtl/Makefile | 2 +- freeldr/freeldr/rtl/list.c | 2 +- freeldr/freeldr/rtl/memory.c | 2 +- freeldr/freeldr/rtl/print.c | 2 +- freeldr/freeldr/rtl/stdlib.c | 2 +- freeldr/freeldr/rtl/string.c | 2 +- freeldr/freeldr/rules.mk | 2 +- freeldr/freeldr/ui.h | 2 +- freeldr/freeldr/ui/Makefile | 2 +- freeldr/freeldr/ui/menu.c | 2 +- freeldr/freeldr/ui/tui.c | 2 +- 56 files changed, 248 insertions(+), 157 deletions(-) create mode 100644 freeldr/freeldr/fs/filesys.h diff --git a/freeldr/freeldr/Makefile b/freeldr/freeldr/Makefile index 85544895108..25d1b0977e7 100644 --- a/freeldr/freeldr/Makefile +++ b/freeldr/freeldr/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/asmcode.S b/freeldr/freeldr/asmcode.S index f4d2913f70d..d638a33a81e 100644 --- a/freeldr/freeldr/asmcode.S +++ b/freeldr/freeldr/asmcode.S @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/asmcode.h b/freeldr/freeldr/asmcode.h index 8d23f3d1e3c..513c2d95772 100644 --- a/freeldr/freeldr/asmcode.h +++ b/freeldr/freeldr/asmcode.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/boot.S b/freeldr/freeldr/boot.S index 6005e312eeb..0a72dba9f58 100644 --- a/freeldr/freeldr/boot.S +++ b/freeldr/freeldr/boot.S @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/cache.h b/freeldr/freeldr/cache.h index b72ed0599e9..ec7e6c5c9f4 100644 --- a/freeldr/freeldr/cache.h +++ b/freeldr/freeldr/cache.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/cache/Makefile b/freeldr/freeldr/cache/Makefile index 2c9d903da9f..9b25a61bff6 100644 --- a/freeldr/freeldr/cache/Makefile +++ b/freeldr/freeldr/cache/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/cache/blocklist.c b/freeldr/freeldr/cache/blocklist.c index 9b341a97869..cde97663775 100644 --- a/freeldr/freeldr/cache/blocklist.c +++ b/freeldr/freeldr/cache/blocklist.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/cache/cache.c b/freeldr/freeldr/cache/cache.c index b69df8c2666..70fc10ab7d2 100644 --- a/freeldr/freeldr/cache/cache.c +++ b/freeldr/freeldr/cache/cache.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/cache/cm.h b/freeldr/freeldr/cache/cm.h index c02c86e987a..df17ab9bf4a 100644 --- a/freeldr/freeldr/cache/cm.h +++ b/freeldr/freeldr/cache/cm.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/comm/Makefile b/freeldr/freeldr/comm/Makefile index f8c5945c600..b543c4f3bfa 100644 --- a/freeldr/freeldr/comm/Makefile +++ b/freeldr/freeldr/comm/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/debug.c b/freeldr/freeldr/debug.c index 697bb37fb97..dfdafbf8975 100644 --- a/freeldr/freeldr/debug.c +++ b/freeldr/freeldr/debug.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/debug.h b/freeldr/freeldr/debug.h index 76430765b20..7ae8c0f062c 100644 --- a/freeldr/freeldr/debug.h +++ b/freeldr/freeldr/debug.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/disk.h b/freeldr/freeldr/disk.h index 76f3807e8d0..016a6a754b0 100644 --- a/freeldr/freeldr/disk.h +++ b/freeldr/freeldr/disk.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/disk/Makefile b/freeldr/freeldr/disk/Makefile index 7621e27a04f..9f95c12cad9 100644 --- a/freeldr/freeldr/disk/Makefile +++ b/freeldr/freeldr/disk/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/disk/disk.c b/freeldr/freeldr/disk/disk.c index d41f3de8b9d..de371cc4c55 100644 --- a/freeldr/freeldr/disk/disk.c +++ b/freeldr/freeldr/disk/disk.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/disk/geometry.c b/freeldr/freeldr/disk/geometry.c index 10ef9b9f55c..e28313f71e7 100644 --- a/freeldr/freeldr/disk/geometry.c +++ b/freeldr/freeldr/disk/geometry.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/freeldr.c b/freeldr/freeldr/freeldr.c index c8b92a1b566..e9642a845c8 100644 --- a/freeldr/freeldr/freeldr.c +++ b/freeldr/freeldr/freeldr.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/freeldr.h b/freeldr/freeldr/freeldr.h index 8834646a9c9..c7f0dbff6fb 100644 --- a/freeldr/freeldr/freeldr.h +++ b/freeldr/freeldr/freeldr.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 @@ -22,8 +22,8 @@ /* just some stuff */ -#define VERSION "FreeLoader v0.8" -#define COPYRIGHT "Copyright (C) 1999, 2000 Brian Palmer " +#define VERSION "FreeLoader v0.9" +#define COPYRIGHT "Copyright (C) 1998-2002 Brian Palmer " #define ROSLDR_MAJOR_VERSION 0 #define ROSLDR_MINOR_VERSION 8 diff --git a/freeldr/freeldr/fs.h b/freeldr/freeldr/fs.h index b0b0edc300b..26aec03dbfa 100644 --- a/freeldr/freeldr/fs.h +++ b/freeldr/freeldr/fs.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 @@ -91,20 +91,8 @@ BOOL IsEndOfFile(PFILE FileHandle); #define EOF -1 -#define ATTR_NORMAL 0x00 -#define ATTR_READONLY 0x01 -#define ATTR_HIDDEN 0x02 -#define ATTR_SYSTEM 0x04 -#define ATTR_VOLUMENAME 0x08 -#define ATTR_DIRECTORY 0x10 -#define ATTR_ARCHIVE 0x20 - #define FS_FAT 1 #define FS_NTFS 2 #define FS_EXT2 3 -#define FAT12 1 -#define FAT16 2 -#define FAT32 3 - #endif // #defined __FS_H diff --git a/freeldr/freeldr/fs/Makefile b/freeldr/freeldr/fs/Makefile index 5989166b749..15bdaec1c07 100644 --- a/freeldr/freeldr/fs/Makefile +++ b/freeldr/freeldr/fs/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/fs/fat.c b/freeldr/freeldr/fs/fat.c index 3cb833559a9..571a9d1cbd7 100644 --- a/freeldr/freeldr/fs/fat.c +++ b/freeldr/freeldr/fs/fat.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 @@ -41,9 +41,13 @@ ULONG FatType = 0; // FAT12, FAT16, or FAT32 ULONG FatDriveNumber = 0; -BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartHead, ULONG VolumeStartTrack, ULONG VolumeStartSector, ULONG FatFileSystemType) +BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartSector) { - FatType = FatFileSystemType; + ULONG PhysicalTrack; + ULONG PhysicalHead; + ULONG PhysicalSector; + + // Store the drive number FatDriveNumber = DriveNumber; // @@ -72,14 +76,32 @@ BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartHead, ULONG VolumeStartTr return FALSE; } - // // Now try to read the boot sector // If this fails then abort - // - if (!BiosInt13Read(DriveNumber, VolumeStartHead, VolumeStartTrack, VolumeStartSector, 1, FatVolumeBootSector)) + if (BiosInt13ExtensionsSupported(DriveNumber)) { - return FALSE; + if (!BiosInt13ReadExtended(DriveNumber, VolumeStartSector, 1, FatVolumeBootSector)) + { + FileSystemError("Disk read error."); + return FALSE; + } } + else + { + // Calculate the physical disk offsets + PhysicalSector = 1 + (VolumeStartSector % get_sectors(DriveNumber)); + PhysicalHead = (VolumeStartSector / get_sectors(DriveNumber)) % get_heads(DriveNumber); + PhysicalTrack = (VolumeStartSector / get_sectors(DriveNumber)) / get_heads(DriveNumber); + + if (!BiosInt13Read(DriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, 1, FatVolumeBootSector)) + { + FileSystemError("Disk read error."); + return FALSE; + } + } + + // Get the FAT type + FatType = FatDetermineFatType(FatVolumeBootSector); #ifdef DEBUG @@ -238,6 +260,38 @@ BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartHead, ULONG VolumeStartTr return TRUE; } +ULONG FatDetermineFatType(PFAT_BOOTSECTOR FatBootSector) +{ + ULONG RootDirSectors; + ULONG DataSectorCount; + ULONG SectorsPerFat; + ULONG TotalSectors; + ULONG CountOfClusters; + PFAT32_BOOTSECTOR Fat32BootSector = (PFAT32_BOOTSECTOR)FatBootSector; + + RootDirSectors = ((FatBootSector->RootDirEntries * 32) + (FatBootSector->BytesPerSector - 1)) / FatBootSector->BytesPerSector; + SectorsPerFat = FatBootSector->SectorsPerFat ? FatBootSector->SectorsPerFat : Fat32BootSector->SectorsPerFatBig; + TotalSectors = FatBootSector->TotalSectors ? FatBootSector->TotalSectors : FatBootSector->TotalSectorsBig; + DataSectorCount = TotalSectors - (FatBootSector->ReservedSectors + (FatBootSector->NumberOfFats * SectorsPerFat) + RootDirSectors); + CountOfClusters = DataSectorCount / FatBootSector->SectorsPerCluster; + + if (CountOfClusters < 4085) + { + /* Volume is FAT12 */ + return FAT12; + } + else if (CountOfClusters < 65525) + { + /* Volume is FAT16 */ + return FAT16; + } + else + { + /* Volume is FAT32 */ + return FAT32; + } +} + PVOID FatBufferDirectory(UINT32 DirectoryStartCluster, PUINT32 EntryCountPointer, BOOL RootDirectory) { UINT32 RootDirectoryStartSector; diff --git a/freeldr/freeldr/fs/fat.h b/freeldr/freeldr/fs/fat.h index 78e468e3a53..c17a0e42495 100644 --- a/freeldr/freeldr/fs/fat.h +++ b/freeldr/freeldr/fs/fat.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 @@ -126,7 +126,8 @@ typedef struct -BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartHead, ULONG VolumeStartTrack, ULONG VolumeStartSector, ULONG FatFileSystemType); +BOOL FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartSector); +ULONG FatDetermineFatType(PFAT_BOOTSECTOR FatBootSector); PVOID FatBufferDirectory(UINT32 DirectoryStartCluster, PUINT32 EntryCountPointer, BOOL RootDirectory); BOOL FatSearchDirectoryBufferForFile(PVOID DirectoryBuffer, UINT32 EntryCount, PUCHAR FileName, PFAT_FILE_INFO FatFileInfoPointer); BOOL FatLookupFile(PUCHAR FileName, PFAT_FILE_INFO FatFileInfoPointer); @@ -147,8 +148,6 @@ ULONG FatGetFilePointer(FILE *FileHandle); BOOL FatReadVolumeSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorCount, PVOID Buffer); -#define EOF -1 - #define ATTR_NORMAL 0x00 #define ATTR_READONLY 0x01 #define ATTR_HIDDEN 0x02 diff --git a/freeldr/freeldr/fs/filesys.h b/freeldr/freeldr/fs/filesys.h new file mode 100644 index 00000000000..5184c8a4766 --- /dev/null +++ b/freeldr/freeldr/fs/filesys.h @@ -0,0 +1,30 @@ +/* + * FreeLoader + * Copyright (C) 1998-2002 Brian Palmer + * + * 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 + +#ifndef __FILESYS_H +#define __FILESYS_H + +BOOL FsInternalIsDiskPartitioned(ULONG DriveNumber); // Returns TRUE if the disk contains partitions, FALSE if floppy disk +BOOL FsInternalGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); // Returns the active partition table entry +BOOL FsInternalGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); // Returns the active partition table entry +ULONG FsInternalGetPartitionCount(ULONG DriveNumber); // Returns the number of partitions on the disk + +#endif // #defined __FILESYS_H diff --git a/freeldr/freeldr/fs/fs.c b/freeldr/freeldr/fs/fs.c index fdcc0f28b60..46883785782 100644 --- a/freeldr/freeldr/fs/fs.c +++ b/freeldr/freeldr/fs/fs.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 @@ -19,6 +19,7 @@ #include #include +#include "filesys.h" #include "fat.h" #include #include @@ -31,10 +32,7 @@ // DATA ///////////////////////////////////////////////////////////////////////////////////////////// -GEOMETRY DriveGeometry; -ULONG VolumeHiddenSectors; -ULONG CurrentlyOpenDriveNumber; -ULONG FileSystemType = 0; // Type of filesystem on boot device, set by OpenDiskDrive() +ULONG FileSystemType = 0; // Type of filesystem on boot device, set by OpenDiskDrive() ///////////////////////////////////////////////////////////////////////////////////////////// // FUNCTIONS @@ -73,27 +71,19 @@ VOID FileSystemError(PUCHAR ErrorString) */ BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber) { - ULONG BootablePartitionCount = 0; - ULONG BootPartition = 0; - ULONG PartitionStartHead; - ULONG PartitionStartSector; - ULONG PartitionStartCylinder; - MASTER_BOOT_RECORD DriveMasterBootRecord; + MASTER_BOOT_RECORD DriveMasterBootRecord; + PARTITION_TABLE_ENTRY PartitionTableEntry; DbgPrint((DPRINT_FILESYSTEM, "OpenDiskDrive() DriveNumber: 0x%x PartitionNumber: 0x%x\n", DriveNumber, PartitionNumber)); - CurrentlyOpenDriveNumber = DriveNumber; - - // // Check and see if it is a floppy drive // If so then just assume FAT12 file system type - // - if (DriveNumber < 0x80) + if (FsInternalIsDiskPartitioned(DriveNumber) == FALSE) { DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n")); FileSystemType = FS_FAT; - return FatOpenVolume(DriveNumber, 0, 0, 1, FAT12); + return FatOpenVolume(DriveNumber, 0); } // @@ -130,98 +120,48 @@ BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber) #endif // defined DEBUG - // // Check the partition table magic value - // if (DriveMasterBootRecord.MasterBootRecordMagic != 0xaa55) { FileSystemError("Invalid partition table magic (0xaa55)"); return FALSE; } + // Get the requested partition entry if (PartitionNumber == 0) { - // - // Count the bootable partitions - // - if (DriveMasterBootRecord.PartitionTable[0].BootIndicator == 0x80) - { - BootablePartitionCount++; - BootPartition = 1; - } - if (DriveMasterBootRecord.PartitionTable[1].BootIndicator == 0x80) - { - BootablePartitionCount++; - BootPartition = 2; - } - if (DriveMasterBootRecord.PartitionTable[2].BootIndicator == 0x80) + // Partition requested was zero which means the boot partition + if (FsInternalGetActivePartitionEntry(DriveNumber, &PartitionTableEntry) == FALSE) { - BootablePartitionCount++; - BootPartition = 3; - } - if (DriveMasterBootRecord.PartitionTable[3].BootIndicator == 0x80) - { - BootablePartitionCount++; - BootPartition = 4; - } - - // - // Make sure there was only one bootable partition - // - if (BootablePartitionCount != 1) - { - FileSystemError("Too many bootable partitions or none found."); return FALSE; } - else + } + else + { + // Get requested partition + if (FsInternalGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry) == FALSE) { - // - // We found the boot partition, so set the partition number - // - PartitionNumber = BootPartition; + return FALSE; } } - // - // Right now the partition number is one-based - // and we need zero based - // - PartitionNumber--; - - // // Check for valid partition - // - if (DriveMasterBootRecord.PartitionTable[PartitionNumber].SystemIndicator == PARTITION_ENTRY_UNUSED) + if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED) { FileSystemError("Invalid partition."); return FALSE; } - PartitionStartHead = DriveMasterBootRecord.PartitionTable[PartitionNumber].StartHead; - PartitionStartSector = DriveMasterBootRecord.PartitionTable[PartitionNumber].StartSector & 0x3F; - PartitionStartCylinder = MAKE_CYLINDER( - DriveMasterBootRecord.PartitionTable[PartitionNumber].StartCylinder, - DriveMasterBootRecord.PartitionTable[PartitionNumber].StartSector); - - DbgPrint((DPRINT_FILESYSTEM, "PartitionStartHead: %d\n", PartitionStartHead)); - DbgPrint((DPRINT_FILESYSTEM, "PartitionStartSector: %d\n", PartitionStartSector)); - DbgPrint((DPRINT_FILESYSTEM, "PartitionStartCylinder: %d\n", PartitionStartCylinder)); - DbgPrint((DPRINT_FILESYSTEM, "PartitionNumber: %d\n", PartitionNumber)); - - switch (DriveMasterBootRecord.PartitionTable[PartitionNumber].SystemIndicator) + switch (PartitionTableEntry.SystemIndicator) { case PARTITION_FAT_12: - FileSystemType = FS_FAT; - return FatOpenVolume(DriveNumber, PartitionStartHead, PartitionStartCylinder, PartitionStartSector, FAT12); case PARTITION_FAT_16: case PARTITION_HUGE: case PARTITION_XINT13: - FileSystemType = FS_FAT; - return FatOpenVolume(DriveNumber, PartitionStartHead, PartitionStartCylinder, PartitionStartSector, FAT16); case PARTITION_FAT32: case PARTITION_FAT32_XINT13: FileSystemType = FS_FAT; - return FatOpenVolume(DriveNumber, PartitionStartHead, PartitionStartCylinder, PartitionStartSector, FAT32); + return FatOpenVolume(DriveNumber, PartitionTableEntry.StartSector); default: FileSystemType = 0; FileSystemError("Unsupported file system."); @@ -231,6 +171,87 @@ BOOL OpenDiskDrive(ULONG DriveNumber, ULONG PartitionNumber) return TRUE; } +BOOL FsInternalIsDiskPartitioned(ULONG DriveNumber) +{ + // Hard disks use drive numbers >= 0x80 + // So if the drive number indicates a hard disk + // then return TRUE + if (DriveNumber >= 0x80) + { + return TRUE; + } + + // Drive is a floppy diskette so return FALSE + return FALSE; +} + +BOOL FsInternalGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry) +{ + ULONG BootablePartitionCount = 0; + MASTER_BOOT_RECORD MasterBootRecord; + + // Read master boot record + if (!BiosInt13Read(DriveNumber, 0, 0, 1, 1, &MasterBootRecord)) + { + FileSystemError("Disk read error."); + return FALSE; + } + + // Count the bootable partitions + if (MasterBootRecord.PartitionTable[0].BootIndicator == 0x80) + { + BootablePartitionCount++; + BootPartition = 0; + } + if (MasterBootRecord.PartitionTable[1].BootIndicator == 0x80) + { + BootablePartitionCount++; + BootPartition = 1; + } + if (MasterBootRecord.PartitionTable[2].BootIndicator == 0x80) + { + BootablePartitionCount++; + BootPartition = 2; + } + if (MasterBootRecord.PartitionTable[3].BootIndicator == 0x80) + { + BootablePartitionCount++; + BootPartition = 3; + } + + // Make sure there was only one bootable partition + if (BootablePartitionCount != 1) + { + FileSystemError("Too many bootable partitions or none found."); + return FALSE; + } + + // Copy the partition table entry + RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[BootPartition], sizeof(PARTITION_TABLE_ENTRY)); + + return TRUE; +} + +BOOL FsInternalGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry) +{ + MASTER_BOOT_RECORD MasterBootRecord; + + // Read master boot record + if (!BiosInt13Read(DriveNumber, 0, 0, 1, 1, &MasterBootRecord)) + { + FileSystemError("Disk read error."); + return FALSE; + } + + // PartitionNumber is one-based and we need it zero-based + PartitionNumber--; + + // Copy the partition table entry + RtlCopyMemory(PartitionTableEntry, &MasterBootRecord.PartitionTable[PartitionNumber], sizeof(PARTITION_TABLE_ENTRY)); + + return TRUE; +} + PFILE OpenFile(PUCHAR FileName) { PFILE FileHandle = NULL; diff --git a/freeldr/freeldr/linux.c b/freeldr/freeldr/linux.c index 7d86177dd42..0e46f52c876 100644 --- a/freeldr/freeldr/linux.c +++ b/freeldr/freeldr/linux.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/linux.h b/freeldr/freeldr/linux.h index 0b319e4b4fb..a8251a4af5a 100644 --- a/freeldr/freeldr/linux.h +++ b/freeldr/freeldr/linux.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/mb.S b/freeldr/freeldr/mb.S index 15f96389809..073753de03a 100644 --- a/freeldr/freeldr/mb.S +++ b/freeldr/freeldr/mb.S @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/mem.S b/freeldr/freeldr/mem.S index 770a1defc42..3b2bc3ee3c8 100644 --- a/freeldr/freeldr/mem.S +++ b/freeldr/freeldr/mem.S @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/miscboot.c b/freeldr/freeldr/miscboot.c index 6bd1a8d952d..7ac55ee5930 100644 --- a/freeldr/freeldr/miscboot.c +++ b/freeldr/freeldr/miscboot.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/miscboot.h b/freeldr/freeldr/miscboot.h index 05226248310..69f3b77de67 100644 --- a/freeldr/freeldr/miscboot.h +++ b/freeldr/freeldr/miscboot.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/mm.h b/freeldr/freeldr/mm.h index 77c3132634b..1252ed7b369 100644 --- a/freeldr/freeldr/mm.h +++ b/freeldr/freeldr/mm.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/mm/Makefile b/freeldr/freeldr/mm/Makefile index c92a8da38cf..2da1fb04fdd 100644 --- a/freeldr/freeldr/mm/Makefile +++ b/freeldr/freeldr/mm/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/mm/mm.c b/freeldr/freeldr/mm/mm.c index 7a652843d5f..67cff795e89 100644 --- a/freeldr/freeldr/mm/mm.c +++ b/freeldr/freeldr/mm/mm.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/multiboot.c b/freeldr/freeldr/multiboot.c index 9b41a810b9c..8f43ac6fe62 100644 --- a/freeldr/freeldr/multiboot.c +++ b/freeldr/freeldr/multiboot.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/options.c b/freeldr/freeldr/options.c index cdb488fed9c..5fe78af35b9 100644 --- a/freeldr/freeldr/options.c +++ b/freeldr/freeldr/options.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/options.h b/freeldr/freeldr/options.h index f408dacb317..d58eb71dda7 100644 --- a/freeldr/freeldr/options.h +++ b/freeldr/freeldr/options.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/oslist.c b/freeldr/freeldr/oslist.c index 06d5f856146..7b54f7802f6 100644 --- a/freeldr/freeldr/oslist.c +++ b/freeldr/freeldr/oslist.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/oslist.h b/freeldr/freeldr/oslist.h index 3ce0e855aa4..d80ab04d0f9 100644 --- a/freeldr/freeldr/oslist.h +++ b/freeldr/freeldr/oslist.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/parseini.c b/freeldr/freeldr/parseini.c index cc2fa82d192..42713da53e9 100644 --- a/freeldr/freeldr/parseini.c +++ b/freeldr/freeldr/parseini.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/parseini.h b/freeldr/freeldr/parseini.h index 23c690fcf67..d799451d1e8 100644 --- a/freeldr/freeldr/parseini.h +++ b/freeldr/freeldr/parseini.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/reactos.h b/freeldr/freeldr/reactos.h index 90631053268..dd39618474f 100644 --- a/freeldr/freeldr/reactos.h +++ b/freeldr/freeldr/reactos.h @@ -1,7 +1,6 @@ /* * FreeLoader - * - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/reactos/Makefile b/freeldr/freeldr/reactos/Makefile index 2972f75f885..1206a5ea2dd 100644 --- a/freeldr/freeldr/reactos/Makefile +++ b/freeldr/freeldr/reactos/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/reactos/hwdetect.h b/freeldr/freeldr/reactos/hwdetect.h index 5bfdac1207e..cacf57ec3ca 100644 --- a/freeldr/freeldr/reactos/hwdetect.h +++ b/freeldr/freeldr/reactos/hwdetect.h @@ -1,7 +1,7 @@ /* * FreeLoader * - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/reactos/reactos.c b/freeldr/freeldr/reactos/reactos.c index 791ffda6210..5930a764905 100644 --- a/freeldr/freeldr/reactos/reactos.c +++ b/freeldr/freeldr/reactos/reactos.c @@ -1,7 +1,7 @@ /* * FreeLoader * - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/rtl.h b/freeldr/freeldr/rtl.h index bdde86502c3..9626f6780c2 100644 --- a/freeldr/freeldr/rtl.h +++ b/freeldr/freeldr/rtl.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/rtl/Makefile b/freeldr/freeldr/rtl/Makefile index 135979103ff..8b76b5d50b0 100644 --- a/freeldr/freeldr/rtl/Makefile +++ b/freeldr/freeldr/rtl/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/rtl/list.c b/freeldr/freeldr/rtl/list.c index 4c812b0c1c2..eb591553366 100644 --- a/freeldr/freeldr/rtl/list.c +++ b/freeldr/freeldr/rtl/list.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/rtl/memory.c b/freeldr/freeldr/rtl/memory.c index 9c0d66226fe..328895f5325 100644 --- a/freeldr/freeldr/rtl/memory.c +++ b/freeldr/freeldr/rtl/memory.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/rtl/print.c b/freeldr/freeldr/rtl/print.c index aada3ed9536..e9101b6ce13 100644 --- a/freeldr/freeldr/rtl/print.c +++ b/freeldr/freeldr/rtl/print.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/rtl/stdlib.c b/freeldr/freeldr/rtl/stdlib.c index e5401ffc200..6bdc954fd22 100644 --- a/freeldr/freeldr/rtl/stdlib.c +++ b/freeldr/freeldr/rtl/stdlib.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/rtl/string.c b/freeldr/freeldr/rtl/string.c index f948643989b..d72053e1727 100644 --- a/freeldr/freeldr/rtl/string.c +++ b/freeldr/freeldr/rtl/string.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/rules.mk b/freeldr/freeldr/rules.mk index cf35b9f45ae..c9642ebee22 100644 --- a/freeldr/freeldr/rules.mk +++ b/freeldr/freeldr/rules.mk @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/ui.h b/freeldr/freeldr/ui.h index 53b0652b6c5..b48d838d4f7 100644 --- a/freeldr/freeldr/ui.h +++ b/freeldr/freeldr/ui.h @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/ui/Makefile b/freeldr/freeldr/ui/Makefile index b51a2b8a41e..d7ba4317472 100644 --- a/freeldr/freeldr/ui/Makefile +++ b/freeldr/freeldr/ui/Makefile @@ -1,6 +1,6 @@ # # FreeLoader -# Copyright (C) 1999, 2000, 2001 Brian Palmer +# Copyright (C) 1998-2002 Brian Palmer # # 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 diff --git a/freeldr/freeldr/ui/menu.c b/freeldr/freeldr/ui/menu.c index 23f37e23102..b26ea2b0c1a 100644 --- a/freeldr/freeldr/ui/menu.c +++ b/freeldr/freeldr/ui/menu.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000, 2001 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 diff --git a/freeldr/freeldr/ui/tui.c b/freeldr/freeldr/ui/tui.c index f0a18bf43e1..a9f0e6926d8 100644 --- a/freeldr/freeldr/ui/tui.c +++ b/freeldr/freeldr/ui/tui.c @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 1999, 2000 Brian Palmer + * Copyright (C) 1998-2002 Brian Palmer * * 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 -- 2.17.1