mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[FREELDR] partition.c: Split the MBR and Xbox (BRFR) code into separate files (#8843)
No actual code changes. Based upon suggestions by Daniel Victor (@iLauncherDev).
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* PROJECT: FreeLoader
|
||||
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||
* PURPOSE: Xbox (BRFR) partitioning scheme support
|
||||
* COPYRIGHT: Copyright 2004 Gé van Geldorp <[email protected]>
|
||||
* Copyright 2019 Stanislav Motylkov <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef _M_ARM
|
||||
// #include <freeldr.h>
|
||||
|
||||
/* BRFR signature at disk offset 0x600 (== 3 * 0x200) */
|
||||
#define XBOX_SIGNATURE_SECTOR 3
|
||||
#define XBOX_SIGNATURE ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
|
||||
|
||||
/* Default hardcoded partition number to boot from Xbox disk */
|
||||
#define FATX_DATA_PARTITION 1
|
||||
|
||||
static struct
|
||||
{
|
||||
ULONG SectorCountBeforePartition;
|
||||
ULONG PartitionSectorCount;
|
||||
UCHAR SystemIndicator;
|
||||
} XboxPartitions[] =
|
||||
{
|
||||
/* This is in the \Device\Harddisk0\Partition.. order used by the Xbox kernel */
|
||||
{ 0x0055F400, 0x0098F800, PARTITION_FAT32 }, /* Store , E: */
|
||||
{ 0x00465400, 0x000FA000, PARTITION_FAT_16 }, /* System, C: */
|
||||
{ 0x00000400, 0x00177000, PARTITION_FAT_16 }, /* Cache1, X: */
|
||||
{ 0x00177400, 0x00177000, PARTITION_FAT_16 }, /* Cache2, Y: */
|
||||
{ 0x002EE400, 0x00177000, PARTITION_FAT_16 } /* Cache3, Z: */
|
||||
};
|
||||
|
||||
BOOLEAN
|
||||
DiskGetBrfrPartitionEntry(
|
||||
IN UCHAR DriveNumber,
|
||||
IN ULONG PartitionNumber,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
/*
|
||||
* Get partition entry of an Xbox-standard BRFR partitioned disk.
|
||||
*/
|
||||
if (PartitionNumber >= 1 && PartitionNumber <= RTL_NUMBER_OF(XboxPartitions) &&
|
||||
MachDiskReadLogicalSectors(DriveNumber, XBOX_SIGNATURE_SECTOR, 1, DiskReadBuffer))
|
||||
{
|
||||
if (*((PULONG)DiskReadBuffer) != XBOX_SIGNATURE)
|
||||
{
|
||||
/* No magic Xbox partitions */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RtlZeroMemory(PartitionTableEntry, sizeof(PARTITION_TABLE_ENTRY));
|
||||
PartitionTableEntry->SystemIndicator = XboxPartitions[PartitionNumber - 1].SystemIndicator;
|
||||
PartitionTableEntry->SectorCountBeforePartition = XboxPartitions[PartitionNumber - 1].SectorCountBeforePartition;
|
||||
PartitionTableEntry->PartitionSectorCount = XboxPartitions[PartitionNumber - 1].PartitionSectorCount;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Partition does not exist */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* PROJECT: FreeLoader
|
||||
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||
* PURPOSE: MBR partitioning scheme support
|
||||
* COPYRIGHT: Copyright 2002-2003 Brian Palmer <[email protected]>
|
||||
* Copyright 2016 Wim Hueskes
|
||||
*/
|
||||
|
||||
#ifndef _M_ARM
|
||||
// #include <freeldr.h>
|
||||
#include "part_mbr.h"
|
||||
|
||||
// #include <debug.h>
|
||||
// DBG_DEFAULT_CHANNEL(DISK);
|
||||
|
||||
static BOOLEAN
|
||||
DiskGetFirstPartitionEntry(
|
||||
IN PMASTER_BOOT_RECORD MasterBootRecord,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
ULONG Index;
|
||||
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
/* Check the system indicator. If it's not an extended or unused partition then we're done. */
|
||||
if ((MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_ENTRY_UNUSED) &&
|
||||
(MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_EXTENDED) &&
|
||||
(MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_XINT13_EXTENDED))
|
||||
{
|
||||
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOLEAN
|
||||
DiskGetFirstExtendedPartitionEntry(
|
||||
IN PMASTER_BOOT_RECORD MasterBootRecord,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
ULONG Index;
|
||||
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
/* Check the system indicator. If it an extended partition then we're done. */
|
||||
if ((MasterBootRecord->PartitionTable[Index].SystemIndicator == PARTITION_EXTENDED) ||
|
||||
(MasterBootRecord->PartitionTable[Index].SystemIndicator == PARTITION_XINT13_EXTENDED))
|
||||
{
|
||||
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
DiskGetActivePartitionEntry(
|
||||
IN UCHAR DriveNumber,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry,
|
||||
OUT PULONG ActivePartition)
|
||||
{
|
||||
ULONG BootablePartitionCount = 0;
|
||||
ULONG CurrentPartitionNumber;
|
||||
ULONG Index;
|
||||
MASTER_BOOT_RECORD MasterBootRecord;
|
||||
PPARTITION_TABLE_ENTRY ThisPartitionTableEntry;
|
||||
|
||||
*ActivePartition = 0;
|
||||
|
||||
/* Read master boot record */
|
||||
if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CurrentPartitionNumber = 0;
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
ThisPartitionTableEntry = &MasterBootRecord.PartitionTable[Index];
|
||||
|
||||
if (ThisPartitionTableEntry->SystemIndicator != PARTITION_ENTRY_UNUSED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_EXTENDED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_XINT13_EXTENDED)
|
||||
{
|
||||
CurrentPartitionNumber++;
|
||||
|
||||
/* Test if this is the bootable partition */
|
||||
if (ThisPartitionTableEntry->BootIndicator == 0x80)
|
||||
{
|
||||
BootablePartitionCount++;
|
||||
*ActivePartition = CurrentPartitionNumber;
|
||||
|
||||
/* Copy the partition table entry */
|
||||
RtlCopyMemory(PartitionTableEntry,
|
||||
ThisPartitionTableEntry,
|
||||
sizeof(PARTITION_TABLE_ENTRY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure there was only one bootable partition */
|
||||
if (BootablePartitionCount == 0)
|
||||
{
|
||||
ERR("No bootable (active) partitions found.\n");
|
||||
return FALSE;
|
||||
}
|
||||
else if (BootablePartitionCount != 1)
|
||||
{
|
||||
ERR("Too many bootable (active) partitions found.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
DiskGetMbrPartitionEntry(
|
||||
IN UCHAR DriveNumber,
|
||||
IN ULONG PartitionNumber,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
MASTER_BOOT_RECORD MasterBootRecord;
|
||||
PARTITION_TABLE_ENTRY ExtendedPartitionTableEntry;
|
||||
ULONG ExtendedPartitionNumber;
|
||||
ULONG ExtendedPartitionOffset;
|
||||
ULONG Index;
|
||||
ULONG CurrentPartitionNumber;
|
||||
PPARTITION_TABLE_ENTRY ThisPartitionTableEntry;
|
||||
|
||||
/* Read master boot record */
|
||||
if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CurrentPartitionNumber = 0;
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
ThisPartitionTableEntry = &MasterBootRecord.PartitionTable[Index];
|
||||
|
||||
if (ThisPartitionTableEntry->SystemIndicator != PARTITION_ENTRY_UNUSED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_EXTENDED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_XINT13_EXTENDED)
|
||||
{
|
||||
CurrentPartitionNumber++;
|
||||
}
|
||||
|
||||
if (PartitionNumber == CurrentPartitionNumber)
|
||||
{
|
||||
RtlCopyMemory(PartitionTableEntry, ThisPartitionTableEntry, sizeof(PARTITION_TABLE_ENTRY));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* They want an extended partition entry so we will need
|
||||
* to loop through all the extended partitions on the disk
|
||||
* and return the one they want.
|
||||
*/
|
||||
ExtendedPartitionNumber = PartitionNumber - CurrentPartitionNumber - 1;
|
||||
|
||||
/*
|
||||
* Set the initial relative starting sector to 0.
|
||||
* This is because extended partition starting
|
||||
* sectors a numbered relative to their parent.
|
||||
*/
|
||||
ExtendedPartitionOffset = 0;
|
||||
|
||||
for (Index = 0; Index <= ExtendedPartitionNumber; Index++)
|
||||
{
|
||||
/* Get the extended partition table entry */
|
||||
if (!DiskGetFirstExtendedPartitionEntry(&MasterBootRecord, &ExtendedPartitionTableEntry))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Adjust the relative starting sector of the partition */
|
||||
ExtendedPartitionTableEntry.SectorCountBeforePartition += ExtendedPartitionOffset;
|
||||
if (ExtendedPartitionOffset == 0)
|
||||
{
|
||||
/* Set the start of the parrent extended partition */
|
||||
ExtendedPartitionOffset = ExtendedPartitionTableEntry.SectorCountBeforePartition;
|
||||
}
|
||||
/* Read the partition boot record */
|
||||
if (!DiskReadBootRecord(DriveNumber, ExtendedPartitionTableEntry.SectorCountBeforePartition, &MasterBootRecord))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Get the first real partition table entry */
|
||||
if (!DiskGetFirstPartitionEntry(&MasterBootRecord, PartitionTableEntry))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Now correct the start sector of the partition */
|
||||
PartitionTableEntry->SectorCountBeforePartition += ExtendedPartitionTableEntry.SectorCountBeforePartition;
|
||||
}
|
||||
|
||||
/*
|
||||
* When we get here we should have the correct entry already
|
||||
* stored in PartitionTableEntry, so just return TRUE.
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* PROJECT: FreeLoader
|
||||
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||
* PURPOSE: MBR partitioning scheme support
|
||||
* COPYRIGHT: Copyright 2002-2003 Brian Palmer <[email protected]>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pshpack1.h>
|
||||
|
||||
/*
|
||||
* Define the structure of a partition table entry
|
||||
*/
|
||||
typedef struct _PARTITION_TABLE_ENTRY
|
||||
{
|
||||
UCHAR BootIndicator; // 0x00 - non-bootable partition,
|
||||
// 0x80 - bootable partition (one partition only)
|
||||
UCHAR StartHead; // Beginning head number
|
||||
UCHAR StartSector; // Beginning sector (2 high bits of cylinder #)
|
||||
UCHAR StartCylinder; // Beginning cylinder# (low order bits of cylinder #)
|
||||
UCHAR SystemIndicator; // System indicator
|
||||
UCHAR EndHead; // Ending head number
|
||||
UCHAR EndSector; // Ending sector (2 high bits of cylinder #)
|
||||
UCHAR EndCylinder; // Ending cylinder# (low order bits of cylinder #)
|
||||
ULONG SectorCountBeforePartition; // Number of sectors preceding the partition
|
||||
ULONG PartitionSectorCount; // Number of sectors in the partition
|
||||
} PARTITION_TABLE_ENTRY, *PPARTITION_TABLE_ENTRY;
|
||||
C_ASSERT(sizeof(PARTITION_TABLE_ENTRY) == 16);
|
||||
|
||||
/*
|
||||
* Define the structure of the master boot record
|
||||
*/
|
||||
typedef struct _MASTER_BOOT_RECORD
|
||||
{
|
||||
UCHAR MasterBootRecordCodeAndData[0x1b8]; /* 0x000 */
|
||||
ULONG Signature; /* 0x1B8 */
|
||||
USHORT Reserved; /* 0x1BC */
|
||||
PARTITION_TABLE_ENTRY PartitionTable[4]; /* 0x1BE */
|
||||
USHORT MasterBootRecordMagic; /* 0x1FE */
|
||||
} MASTER_BOOT_RECORD, *PMASTER_BOOT_RECORD;
|
||||
C_ASSERT(sizeof(MASTER_BOOT_RECORD) == 512);
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
/*
|
||||
* Partition type defines (of PSDK)
|
||||
*/
|
||||
#include <reactos/rosioctl.h>
|
||||
#define PARTITION_ENTRY_UNUSED 0x00 // Entry unused
|
||||
#define PARTITION_FAT_12 0x01 // 12-bit FAT entries
|
||||
#define PARTITION_XENIX_1 0x02 // Xenix
|
||||
#define PARTITION_XENIX_2 0x03 // Xenix
|
||||
#define PARTITION_FAT_16 0x04 // 16-bit FAT entries
|
||||
#define PARTITION_EXTENDED 0x05 // Extended partition entry
|
||||
#define PARTITION_HUGE 0x06 // Huge partition MS-DOS V4
|
||||
#define PARTITION_IFS 0x07 // IFS Partition
|
||||
#define PARTITION_OS2BOOTMGR 0x0A // OS/2 Boot Manager/OPUS/Coherent swap
|
||||
#define PARTITION_FAT32 0x0B // FAT32
|
||||
#define PARTITION_FAT32_XINT13 0x0C // FAT32 using extended int13 services
|
||||
#define PARTITION_XINT13 0x0E // Win95 partition using extended int13 services
|
||||
#define PARTITION_XINT13_EXTENDED 0x0F // Same as type 5 but uses extended int13 services
|
||||
#define PARTITION_NTFS 0x17 // NTFS
|
||||
#define PARTITION_PREP 0x41 // PowerPC Reference Platform (PReP) Boot Partition
|
||||
#define PARTITION_LDM 0x42 // Logical Disk Manager partition
|
||||
#define PARTITION_UNIX 0x63 // Unix
|
||||
#define VALID_NTFT 0xC0 // NTFT uses high order bits
|
||||
#define PARTITION_NTFT 0x80 // NTFT partition
|
||||
#define PARTITION_GPT 0xEE // GPT protective partition
|
||||
#ifdef __REACTOS__
|
||||
#define PARTITION_OLD_LINUX 0x43
|
||||
#define PARTITION_LINUX 0x83
|
||||
#endif
|
||||
@@ -1,20 +1,9 @@
|
||||
/*
|
||||
* FreeLoader
|
||||
* Copyright (C) 1998-2003 Brian Palmer <[email protected]>
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
* PROJECT: FreeLoader
|
||||
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||
* PURPOSE: Block Device partition management
|
||||
* COPYRIGHT: Copyright 2002-2003 Brian Palmer <[email protected]>
|
||||
* Copyright 2019 Stanislav Motylkov <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef _M_ARM
|
||||
@@ -26,29 +15,7 @@ DBG_DEFAULT_CHANNEL(DISK);
|
||||
#define MaxDriveNumber 0xFF
|
||||
static PARTITION_STYLE DiskPartitionType[MaxDriveNumber + 1];
|
||||
|
||||
/* BRFR signature at disk offset 0x600 */
|
||||
#define XBOX_SIGNATURE_SECTOR 3
|
||||
#define XBOX_SIGNATURE ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
|
||||
|
||||
/* Default hardcoded partition number to boot from Xbox disk */
|
||||
#define FATX_DATA_PARTITION 1
|
||||
|
||||
static struct
|
||||
{
|
||||
ULONG SectorCountBeforePartition;
|
||||
ULONG PartitionSectorCount;
|
||||
UCHAR SystemIndicator;
|
||||
} XboxPartitions[] =
|
||||
{
|
||||
/* This is in the \Device\Harddisk0\Partition.. order used by the Xbox kernel */
|
||||
{ 0x0055F400, 0x0098F800, PARTITION_FAT32 }, /* Store , E: */
|
||||
{ 0x00465400, 0x000FA000, PARTITION_FAT_16 }, /* System, C: */
|
||||
{ 0x00000400, 0x00177000, PARTITION_FAT_16 }, /* Cache1, X: */
|
||||
{ 0x00177400, 0x00177000, PARTITION_FAT_16 }, /* Cache2, Y: */
|
||||
{ 0x002EE400, 0x00177000, PARTITION_FAT_16 } /* Cache3, Z: */
|
||||
};
|
||||
|
||||
static BOOLEAN
|
||||
BOOLEAN
|
||||
DiskReadBootRecord(
|
||||
IN UCHAR DriveNumber,
|
||||
IN ULONGLONG LogicalSectorNumber,
|
||||
@@ -87,228 +54,8 @@ DiskReadBootRecord(
|
||||
return (BootRecord->MasterBootRecordMagic == 0xaa55);
|
||||
}
|
||||
|
||||
static BOOLEAN
|
||||
DiskGetFirstPartitionEntry(
|
||||
IN PMASTER_BOOT_RECORD MasterBootRecord,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
ULONG Index;
|
||||
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
/* Check the system indicator. If it's not an extended or unused partition then we're done. */
|
||||
if ((MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_ENTRY_UNUSED) &&
|
||||
(MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_EXTENDED) &&
|
||||
(MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_XINT13_EXTENDED))
|
||||
{
|
||||
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOLEAN
|
||||
DiskGetFirstExtendedPartitionEntry(
|
||||
IN PMASTER_BOOT_RECORD MasterBootRecord,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
ULONG Index;
|
||||
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
/* Check the system indicator. If it an extended partition then we're done. */
|
||||
if ((MasterBootRecord->PartitionTable[Index].SystemIndicator == PARTITION_EXTENDED) ||
|
||||
(MasterBootRecord->PartitionTable[Index].SystemIndicator == PARTITION_XINT13_EXTENDED))
|
||||
{
|
||||
RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOLEAN
|
||||
DiskGetActivePartitionEntry(
|
||||
IN UCHAR DriveNumber,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry,
|
||||
OUT PULONG ActivePartition)
|
||||
{
|
||||
ULONG BootablePartitionCount = 0;
|
||||
ULONG CurrentPartitionNumber;
|
||||
ULONG Index;
|
||||
MASTER_BOOT_RECORD MasterBootRecord;
|
||||
PPARTITION_TABLE_ENTRY ThisPartitionTableEntry;
|
||||
|
||||
*ActivePartition = 0;
|
||||
|
||||
/* Read master boot record */
|
||||
if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CurrentPartitionNumber = 0;
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
ThisPartitionTableEntry = &MasterBootRecord.PartitionTable[Index];
|
||||
|
||||
if (ThisPartitionTableEntry->SystemIndicator != PARTITION_ENTRY_UNUSED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_EXTENDED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_XINT13_EXTENDED)
|
||||
{
|
||||
CurrentPartitionNumber++;
|
||||
|
||||
/* Test if this is the bootable partition */
|
||||
if (ThisPartitionTableEntry->BootIndicator == 0x80)
|
||||
{
|
||||
BootablePartitionCount++;
|
||||
*ActivePartition = CurrentPartitionNumber;
|
||||
|
||||
/* Copy the partition table entry */
|
||||
RtlCopyMemory(PartitionTableEntry,
|
||||
ThisPartitionTableEntry,
|
||||
sizeof(PARTITION_TABLE_ENTRY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure there was only one bootable partition */
|
||||
if (BootablePartitionCount == 0)
|
||||
{
|
||||
ERR("No bootable (active) partitions found.\n");
|
||||
return FALSE;
|
||||
}
|
||||
else if (BootablePartitionCount != 1)
|
||||
{
|
||||
ERR("Too many bootable (active) partitions found.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOLEAN
|
||||
DiskGetMbrPartitionEntry(
|
||||
IN UCHAR DriveNumber,
|
||||
IN ULONG PartitionNumber,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
MASTER_BOOT_RECORD MasterBootRecord;
|
||||
PARTITION_TABLE_ENTRY ExtendedPartitionTableEntry;
|
||||
ULONG ExtendedPartitionNumber;
|
||||
ULONG ExtendedPartitionOffset;
|
||||
ULONG Index;
|
||||
ULONG CurrentPartitionNumber;
|
||||
PPARTITION_TABLE_ENTRY ThisPartitionTableEntry;
|
||||
|
||||
/* Read master boot record */
|
||||
if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CurrentPartitionNumber = 0;
|
||||
for (Index = 0; Index < 4; Index++)
|
||||
{
|
||||
ThisPartitionTableEntry = &MasterBootRecord.PartitionTable[Index];
|
||||
|
||||
if (ThisPartitionTableEntry->SystemIndicator != PARTITION_ENTRY_UNUSED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_EXTENDED &&
|
||||
ThisPartitionTableEntry->SystemIndicator != PARTITION_XINT13_EXTENDED)
|
||||
{
|
||||
CurrentPartitionNumber++;
|
||||
}
|
||||
|
||||
if (PartitionNumber == CurrentPartitionNumber)
|
||||
{
|
||||
RtlCopyMemory(PartitionTableEntry, ThisPartitionTableEntry, sizeof(PARTITION_TABLE_ENTRY));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* They want an extended partition entry so we will need
|
||||
* to loop through all the extended partitions on the disk
|
||||
* and return the one they want.
|
||||
*/
|
||||
ExtendedPartitionNumber = PartitionNumber - CurrentPartitionNumber - 1;
|
||||
|
||||
/*
|
||||
* Set the initial relative starting sector to 0.
|
||||
* This is because extended partition starting
|
||||
* sectors a numbered relative to their parent.
|
||||
*/
|
||||
ExtendedPartitionOffset = 0;
|
||||
|
||||
for (Index = 0; Index <= ExtendedPartitionNumber; Index++)
|
||||
{
|
||||
/* Get the extended partition table entry */
|
||||
if (!DiskGetFirstExtendedPartitionEntry(&MasterBootRecord, &ExtendedPartitionTableEntry))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Adjust the relative starting sector of the partition */
|
||||
ExtendedPartitionTableEntry.SectorCountBeforePartition += ExtendedPartitionOffset;
|
||||
if (ExtendedPartitionOffset == 0)
|
||||
{
|
||||
/* Set the start of the parrent extended partition */
|
||||
ExtendedPartitionOffset = ExtendedPartitionTableEntry.SectorCountBeforePartition;
|
||||
}
|
||||
/* Read the partition boot record */
|
||||
if (!DiskReadBootRecord(DriveNumber, ExtendedPartitionTableEntry.SectorCountBeforePartition, &MasterBootRecord))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Get the first real partition table entry */
|
||||
if (!DiskGetFirstPartitionEntry(&MasterBootRecord, PartitionTableEntry))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Now correct the start sector of the partition */
|
||||
PartitionTableEntry->SectorCountBeforePartition += ExtendedPartitionTableEntry.SectorCountBeforePartition;
|
||||
}
|
||||
|
||||
/*
|
||||
* When we get here we should have the correct entry already
|
||||
* stored in PartitionTableEntry, so just return TRUE.
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOLEAN
|
||||
DiskGetBrfrPartitionEntry(
|
||||
IN UCHAR DriveNumber,
|
||||
IN ULONG PartitionNumber,
|
||||
OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
|
||||
{
|
||||
/*
|
||||
* Get partition entry of an Xbox-standard BRFR partitioned disk.
|
||||
*/
|
||||
if (PartitionNumber >= 1 && PartitionNumber <= sizeof(XboxPartitions) / sizeof(XboxPartitions[0]) &&
|
||||
MachDiskReadLogicalSectors(DriveNumber, XBOX_SIGNATURE_SECTOR, 1, DiskReadBuffer))
|
||||
{
|
||||
if (*((PULONG)DiskReadBuffer) != XBOX_SIGNATURE)
|
||||
{
|
||||
/* No magic Xbox partitions */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RtlZeroMemory(PartitionTableEntry, sizeof(PARTITION_TABLE_ENTRY));
|
||||
PartitionTableEntry->SystemIndicator = XboxPartitions[PartitionNumber - 1].SystemIndicator;
|
||||
PartitionTableEntry->SectorCountBeforePartition = XboxPartitions[PartitionNumber - 1].SectorCountBeforePartition;
|
||||
PartitionTableEntry->PartitionSectorCount = XboxPartitions[PartitionNumber - 1].PartitionSectorCount;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Partition does not exist */
|
||||
return FALSE;
|
||||
}
|
||||
#include "part_mbr.c"
|
||||
#include "part_brfr.c"
|
||||
|
||||
VOID
|
||||
DiskDetectPartitionType(
|
||||
@@ -363,6 +110,7 @@ DiskDetectPartitionType(
|
||||
TRACE("Drive 0x%X partition type unknown\n", DriveNumber);
|
||||
}
|
||||
|
||||
// FIXME: This function is specific to BIOS-based PC platform.
|
||||
BOOLEAN
|
||||
DiskGetBootPartitionEntry(
|
||||
IN UCHAR DriveNumber,
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <reactos/rosioctl.h>
|
||||
|
||||
/* FreeLoader-specific disk geometry structure */
|
||||
typedef struct _GEOMETRY
|
||||
{
|
||||
@@ -31,67 +29,26 @@ typedef struct _GEOMETRY
|
||||
ULONGLONG Sectors; ///< Total number of disk sectors/LBA blocks
|
||||
} GEOMETRY, *PGEOMETRY;
|
||||
|
||||
#include <pshpack1.h>
|
||||
|
||||
/*
|
||||
* Define the structure of a partition table entry
|
||||
*/
|
||||
typedef struct _PARTITION_TABLE_ENTRY
|
||||
{
|
||||
UCHAR BootIndicator; // 0x00 - non-bootable partition,
|
||||
// 0x80 - bootable partition (one partition only)
|
||||
UCHAR StartHead; // Beginning head number
|
||||
UCHAR StartSector; // Beginning sector (2 high bits of cylinder #)
|
||||
UCHAR StartCylinder; // Beginning cylinder# (low order bits of cylinder #)
|
||||
UCHAR SystemIndicator; // System indicator
|
||||
UCHAR EndHead; // Ending head number
|
||||
UCHAR EndSector; // Ending sector (2 high bits of cylinder #)
|
||||
UCHAR EndCylinder; // Ending cylinder# (low order bits of cylinder #)
|
||||
ULONG SectorCountBeforePartition; // Number of sectors preceding the partition
|
||||
ULONG PartitionSectorCount; // Number of sectors in the partition
|
||||
} PARTITION_TABLE_ENTRY, *PPARTITION_TABLE_ENTRY;
|
||||
|
||||
/*
|
||||
* Define the structure of the master boot record
|
||||
*/
|
||||
typedef struct _MASTER_BOOT_RECORD
|
||||
{
|
||||
UCHAR MasterBootRecordCodeAndData[0x1b8]; /* 0x000 */
|
||||
ULONG Signature; /* 0x1B8 */
|
||||
USHORT Reserved; /* 0x1BC */
|
||||
PARTITION_TABLE_ENTRY PartitionTable[4]; /* 0x1BE */
|
||||
USHORT MasterBootRecordMagic; /* 0x1FE */
|
||||
} MASTER_BOOT_RECORD, *PMASTER_BOOT_RECORD;
|
||||
|
||||
#include <poppack.h>
|
||||
// Some modules use the explicit MBR structures. TODO: Deprecate
|
||||
#include "disk/part_mbr.h"
|
||||
|
||||
/*
|
||||
* Partition type defines (of PSDK)
|
||||
*/
|
||||
#define PARTITION_ENTRY_UNUSED 0x00 // Entry unused
|
||||
#define PARTITION_FAT_12 0x01 // 12-bit FAT entries
|
||||
#define PARTITION_XENIX_1 0x02 // Xenix
|
||||
#define PARTITION_XENIX_2 0x03 // Xenix
|
||||
#define PARTITION_FAT_16 0x04 // 16-bit FAT entries
|
||||
#define PARTITION_EXTENDED 0x05 // Extended partition entry
|
||||
#define PARTITION_HUGE 0x06 // Huge partition MS-DOS V4
|
||||
#define PARTITION_IFS 0x07 // IFS Partition
|
||||
#define PARTITION_OS2BOOTMGR 0x0A // OS/2 Boot Manager/OPUS/Coherent swap
|
||||
#define PARTITION_FAT32 0x0B // FAT32
|
||||
#define PARTITION_FAT32_XINT13 0x0C // FAT32 using extended int13 services
|
||||
#define PARTITION_XINT13 0x0E // Win95 partition using extended int13 services
|
||||
#define PARTITION_XINT13_EXTENDED 0x0F // Same as type 5 but uses extended int13 services
|
||||
#define PARTITION_NTFS 0x17 // NTFS
|
||||
#define PARTITION_PREP 0x41 // PowerPC Reference Platform (PReP) Boot Partition
|
||||
#define PARTITION_LDM 0x42 // Logical Disk Manager partition
|
||||
#define PARTITION_UNIX 0x63 // Unix
|
||||
#define VALID_NTFT 0xC0 // NTFT uses high order bits
|
||||
#define PARTITION_NTFT 0x80 // NTFT partition
|
||||
#define PARTITION_GPT 0xEE // GPT protective partition
|
||||
#ifdef __REACTOS__
|
||||
#define PARTITION_OLD_LINUX 0x43
|
||||
#define PARTITION_LINUX 0x83
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user